annotate src/cs/drivers/drv_app/fchg/fchg_default_batt.c @ 516:1ed9de6c90bd

src/g23m-gsm/sms/sms_for.c: bogus malloc removed The new error handling code that was not present in TCS211 blob version contains a malloc call that is bogus for 3 reasons: 1) The memory allocation in question is not needed in the first place; 2) libc malloc is used instead of one of the firmware's proper ways; 3) The memory allocation is made inside a function and then never freed, i.e., a memory leak. This bug was caught in gcc-built FreeCalypso fw projects (Citrine and Selenite) because our gcc environment does not allow any use of libc malloc (any reference to malloc produces a link failure), but this code from TCS3.2 is wrong even for Magnetite: if this code path is executed repeatedly over a long time, the many small allocations made by this malloc call without a subsequent free will eventually exhaust the malloc heap provided by the TMS470 environment, malloc will start returning NULL, and the bogus code will treat it as an error. Because the memory allocation in question is not needed at all, the fix entails simply removing it.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 22 Jul 2018 06:04:49 +0000
parents 919b44c991fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
324
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module provides the default table of battery State-of-Charge
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * thresholds in the absence of a customized table in FFS.
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * The present default table has been taken from Pirelli's firmware.
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "fchg/fchg_env.h"
326
919b44c991fc FCHG: reading of battery table from FFS implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 324
diff changeset
9 #include "fchg/fchg_func_i.h"
324
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "rv/rv_general.h"
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static const T_PWR_THRESHOLDS default_batt_table[] = {
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {4170, 100},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {4120, 95},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {4070, 90},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {4030, 85},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {3964, 80},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {3930, 75},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 {3900, 70},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {3882, 65},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {3847, 60},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {3805, 55},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {3786, 50},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {3771, 45},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {3759, 40},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {3750, 35},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {3745, 30},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {3737, 25},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {3719, 20},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {3688, 15},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {3663, 10},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {3539, 5},
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {3370, 0}
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 };
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 void pwr_set_default_batt_table(void)
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 memcpy(pwr_ctrl->batt_thresholds, default_batt_table,
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 sizeof default_batt_table);
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 pwr_ctrl->nb_thresholds = sizeof(default_batt_table) /
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 sizeof(T_PWR_THRESHOLDS);
6ab14029931c FCHG: default battery table implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }