Skip to contentSkip to conversation

thermal: cpu_cooling: check for allocation failure

PATCH In review Dan Carpenter 2 participants 2 messages Mar 30, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: cpu_cooling: check for allocation failure

If this fails, then we're likely in trouble anyway, but it's nice to keep the code free from static checker warnings so you don't miss more important bugs.

drivers/thermal/cpu_cooling.c +4 -0
index c497414..3a01dfd 100644
@@ -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 lore raw
Quoted 11 lines · Dan Carpenter

If this fails, then we're likely in trouble anyway, but it's nice to keep the code free from static checker warnings so you don't miss more important bugs.

drivers/thermal/cpu_cooling.c +0 -0
index c497414..3a01dfd 100644

drivers/thermal/cpu_cooling.c static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, · line 335

Quoted 7 lines
drivers/thermal/cpu_cooling.c +4 -0
@@ -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;
+	}

This fix is already in Eduardo's tree and is scheduled for 4.1:

https://git.kernel.org/cgit/linux/kernel/git/evalenti/linux-soc-thermal.git/commit/?h=linus&idea7db8371d1203adb871d240d46b040fd6b4e1d

Cheers,
Javi