diff mbox

thermal: cpu_cooling: Check memory allocation of power_table

Message ID 1426875613-31612-1-git-send-email-javi.merino@arm.com (mailing list archive)
State Accepted
Delegated to: Eduardo Valentin
Headers show

Commit Message

Javi Merino March 20, 2015, 6:20 p.m. UTC
We allocate the power_table in memory but we don't test whether the
allocation succeeded.  Return -ENOMEM if kcalloc() fails.

Fixes: e0128d8ab423 ("thermal: cpu_cooling: implement the power cooling device API")
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Zhang Rui <rui.zhang@intel.com>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Javi Merino <javi.merino@arm.com>
---
This applies on top of the linus branch in Eduardo's repository

 drivers/thermal/cpu_cooling.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Javi Merino March 25, 2015, 11:47 a.m. UTC | #1
On Fri, Mar 20, 2015 at 06:20:13PM +0000, Javi Merino wrote:
> We allocate the power_table in memory but we don't test whether the
> allocation succeeded.  Return -ENOMEM if kcalloc() fails.
> 
> Fixes: e0128d8ab423 ("thermal: cpu_cooling: implement the power cooling device API")
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Zhang Rui <rui.zhang@intel.com>
> Reported-by: kbuild test robot <fengguang.wu@intel.com>
> Signed-off-by: Javi Merino <javi.merino@arm.com>
> ---
> This applies on top of the linus branch in Eduardo's repository
> 
>  drivers/thermal/cpu_cooling.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
> index c4974144c787..3a01dfd5b29c 100644
> --- a/drivers/thermal/cpu_cooling.c
> +++ b/drivers/thermal/cpu_cooling.c
> @@ -329,6 +329,10 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device,
>  	}
>  
>  	power_table = kcalloc(num_opps, sizeof(*power_table), GFP_KERNEL);
> +	if (!power_table) {
> +		ret = -ENOMEM;
> +		goto unlock;
> +	}
>  
>  	for (freq = 0, i = 0;
>  	     opp = dev_pm_opp_find_freq_ceil(dev, &freq), !IS_ERR(opp);
> -- 
> 1.9.1

Gentle reminder.  Cheers,
Javi

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index c4974144c787..3a01dfd5b29c 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -329,6 +329,10 @@  static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device,
 	}
 
 	power_table = kcalloc(num_opps, sizeof(*power_table), GFP_KERNEL);
+	if (!power_table) {
+		ret = -ENOMEM;
+		goto unlock;
+	}
 
 	for (freq = 0, i = 0;
 	     opp = dev_pm_opp_find_freq_ceil(dev, &freq), !IS_ERR(opp);