aboutsummaryrefslogtreecommitdiff
path: root/hw/occ.c
diff options
context:
space:
mode:
authorVaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>2014-11-22 00:09:32 +0530
committerStewart Smith <stewart@linux.vnet.ibm.com>2014-11-25 17:34:23 +1100
commit82b950bc00a61f0c18634ede0df09fd5fcbc8a59 (patch)
tree59b855cfe18919dbaa8a58bf19e5c06431ca348f /hw/occ.c
parentc1c290227ec4111fa6c406307fd04f588280ec13 (diff)
downloadskiboot-82b950bc00a61f0c18634ede0df09fd5fcbc8a59.zip
skiboot-82b950bc00a61f0c18634ede0df09fd5fcbc8a59.tar.gz
skiboot-82b950bc00a61f0c18634ede0df09fd5fcbc8a59.tar.bz2
occ: Reduce stack usage in add_cpu_pstate_properties()
This function uses int arrays from stack that pushes stack usage to more than 2kB. Reduce stack usage by allocating memory. Ben H's stack check compile option exposed this usage count: hw/occ.c: In function 'add_cpu_pstate_properties': hw/occ.c:187:1: warning: the frame size of 2064 bytes is larger than 2048 bytes [-Wframe-larger-than=] Signed-off-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'hw/occ.c')
-rw-r--r--hw/occ.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/hw/occ.c b/hw/occ.c
index 8b08fd1..c5ecccd 100644
--- a/hw/occ.c
+++ b/hw/occ.c
@@ -126,8 +126,7 @@ static bool add_cpu_pstate_properties(s8 *pstate_nom)
struct dt_node *power_mgt;
u8 nr_pstates;
/* Arrays for device tree */
- u32 dt_id[MAX_PSTATES];
- u32 dt_freq[MAX_PSTATES];
+ u32 *dt_id, *dt_freq;
int i;
printf("OCC: CPU pstate state device tree init\n");
@@ -162,18 +161,32 @@ static bool add_cpu_pstate_properties(s8 *pstate_nom)
return false;
}
- /* Setup arrays for device-tree */
- for( i=0; i < nr_pstates; i++) {
- dt_id[i] = occ_data->pstates[i].id;
- dt_freq[i] = occ_data->pstates[i].freq_khz/1000;
- }
-
power_mgt = dt_find_by_path(dt_root, "/ibm,opal/power-mgt");
if (!power_mgt) {
printf("OCC: dt node /ibm,opal/power-mgt not found\n");
return false;
}
+ /* Setup arrays for device-tree */
+ /* Allocate memory */
+ dt_id = (u32 *) malloc(MAX_PSTATES * sizeof(u32));
+ if (!dt_id) {
+ printf("OCC: dt_id array alloc failure\n");
+ return false;
+ }
+
+ dt_freq = (u32 *) malloc(MAX_PSTATES * sizeof(u32));
+ if (!dt_freq) {
+ printf("OCC: dt_freq array alloc failure\n");
+ free(dt_id);
+ return false;
+ }
+
+ for( i=0; i < nr_pstates; i++) {
+ dt_id[i] = occ_data->pstates[i].id;
+ dt_freq[i] = occ_data->pstates[i].freq_khz/1000;
+ }
+
/* Add the device-tree entries */
dt_add_property(power_mgt, "ibm,pstate-ids", dt_id, nr_pstates * 4);
dt_add_property(power_mgt, "ibm,pstate-frequencies-mhz", dt_freq, nr_pstates * 4);
@@ -183,6 +196,9 @@ static bool add_cpu_pstate_properties(s8 *pstate_nom)
/* Return pstate to set for each core */
*pstate_nom = occ_data->pstate_nom;
+ /* Free memory */
+ free(dt_id);
+ free(dt_freq);
return true;
}