diff options
| author | Yangtao Li <tiny.windzz@gmail.com> | 2019-02-16 12:06:23 -0500 |
|---|---|---|
| committer | Viresh Kumar <viresh.kumar@linaro.org> | 2019-02-17 23:57:38 -0500 |
| commit | 5ae06c237fd05a1e9acf6f35891cfd85de792521 (patch) | |
| tree | 5dc3791fcfe79daf0c69a37fbf0eaa9c3b637568 | |
| parent | 2814335cb3c8b364dcc740b6317bd3297e81995c (diff) | |
cpufreq: powernv: fix missing check of return value in init_powernv_pstates()
kmalloc() could fail, so insert a check of its return value. And
if it fails, returns -ENOMEM.
And remove (struct pstate_idx_revmap_data *) to fix coccinelle WARNING
by the way.
WARNING: casting value returned by memory allocation function to (struct
pstate_idx_revmap_data *) is useless.
Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
| -rw-r--r-- | drivers/cpufreq/powernv-cpufreq.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c index 7e7ad3879c4e..d2230812fa4b 100644 --- a/drivers/cpufreq/powernv-cpufreq.c +++ b/drivers/cpufreq/powernv-cpufreq.c | |||
| @@ -244,6 +244,7 @@ static int init_powernv_pstates(void) | |||
| 244 | u32 len_ids, len_freqs; | 244 | u32 len_ids, len_freqs; |
| 245 | u32 pstate_min, pstate_max, pstate_nominal; | 245 | u32 pstate_min, pstate_max, pstate_nominal; |
| 246 | u32 pstate_turbo, pstate_ultra_turbo; | 246 | u32 pstate_turbo, pstate_ultra_turbo; |
| 247 | int rc = -ENODEV; | ||
| 247 | 248 | ||
| 248 | power_mgt = of_find_node_by_path("/ibm,opal/power-mgt"); | 249 | power_mgt = of_find_node_by_path("/ibm,opal/power-mgt"); |
| 249 | if (!power_mgt) { | 250 | if (!power_mgt) { |
| @@ -327,8 +328,11 @@ next: | |||
| 327 | powernv_freqs[i].frequency = freq * 1000; /* kHz */ | 328 | powernv_freqs[i].frequency = freq * 1000; /* kHz */ |
| 328 | powernv_freqs[i].driver_data = id & 0xFF; | 329 | powernv_freqs[i].driver_data = id & 0xFF; |
| 329 | 330 | ||
| 330 | revmap_data = (struct pstate_idx_revmap_data *) | 331 | revmap_data = kmalloc(sizeof(*revmap_data), GFP_KERNEL); |
| 331 | kmalloc(sizeof(*revmap_data), GFP_KERNEL); | 332 | if (!revmap_data) { |
| 333 | rc = -ENOMEM; | ||
| 334 | goto out; | ||
| 335 | } | ||
| 332 | 336 | ||
| 333 | revmap_data->pstate_id = id & 0xFF; | 337 | revmap_data->pstate_id = id & 0xFF; |
| 334 | revmap_data->cpufreq_table_idx = i; | 338 | revmap_data->cpufreq_table_idx = i; |
| @@ -357,7 +361,7 @@ next: | |||
| 357 | return 0; | 361 | return 0; |
| 358 | out: | 362 | out: |
| 359 | of_node_put(power_mgt); | 363 | of_node_put(power_mgt); |
| 360 | return -ENODEV; | 364 | return rc; |
| 361 | } | 365 | } |
| 362 | 366 | ||
| 363 | /* Returns the CPU frequency corresponding to the pstate_id. */ | 367 | /* Returns the CPU frequency corresponding to the pstate_id. */ |
