From 0cdf97e1ad8d796313de051528f06c1b16f3a679 Mon Sep 17 00:00:00 2001 From: Javi Merino Date: Fri, 20 Mar 2015 18:20:13 +0000 Subject: [PATCH] thermal: cpu_cooling: Check memory allocation of power_table 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 Cc: Zhang Rui Reported-by: kbuild test robot Signed-off-by: Javi Merino Signed-off-by: Eduardo Valentin --- 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); -- 2.34.1