Skip to contentSkip to conversation

thermal: cpu_cooling: Use kmalloc_array() in __cpufreq_cooling_register()

PATCH In review SF Markus Elfring 2 participants 2 messages Apr 10, 2017 – Apr 11, 2017

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

PATCH 1/1 thermal: cpu_cooling: Use kmalloc_array() in __cpufreq_cooling_register()

From: Markus Elfring <[email protected]>
Date: Mon, 10 Apr 2017 17:00:13 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/cpu_cooling.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/cpu_cooling.c +3 -2
index 69d0f430b2d1..273d9d5dbe0f 100644
@@ -823,8 +823,9 @@ __cpufreq_cooling_register(struct device_node *np,
 	cpufreq_for_each_valid_entry(pos, table)
 		cpufreq_dev->max_level++;
 
-	cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) *
-					  cpufreq_dev->max_level, GFP_KERNEL);
+	cpufreq_dev->freq_table = kmalloc_array(cpufreq_dev->max_level,
+						sizeof(*cpufreq_dev->freq_table),
+						GFP_KERNEL);
 	if (!cpufreq_dev->freq_table) {
 		cool_dev = ERR_PTR(-ENOMEM);
 		goto free_time_in_idle_timestamp;
Signature · 1 line
2.12.2
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 10 Apr 2017 17:00:13 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/cpu_cooling.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/cpu_cooling.c +0 -0
index 69d0f430b2d1..273d9d5dbe0f 100644
@@ -823,8 +823,9 @@ __cpufreq_cooling_register(struct device_node *np,
 	cpufreq_for_each_valid_entry(pos, table)

drivers/thermal/cpu_cooling.c __cpufreq_cooling_register(struct device_node *np, · line 831

Quoted 10 lines
drivers/thermal/cpu_cooling.c +3 -2
 		cpufreq_dev->max_level++;
 
-	cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) *
-					  cpufreq_dev->max_level, GFP_KERNEL);
+	cpufreq_dev->freq_table = kmalloc_array(cpufreq_dev->max_level,
+						sizeof(*cpufreq_dev->freq_table),
+						GFP_KERNEL);
 	if (!cpufreq_dev->freq_table) {
 		cool_dev = ERR_PTR(-ENOMEM);
 		goto free_time_in_idle_timestamp;
Signature · 1 line
viresh