Skip to contentSkip to conversation

thermal: devfreq_cooling: avoid unnecessary kfree of freq_table

PATCH Applied Anas Iqbal 3 participants 3 messages Mar 23 Thermal

lore
Share & tools
lore

Anas Iqbal

author
#0 lore raw

PATCH 1/1 thermal: devfreq_cooling: avoid unnecessary kfree of freq_table

dfc->freq_table is only allocated in the non-EM path via devfreq_cooling_gen_tables(). In the EM path, it remains NULL.

Avoid calling kfree() unnecessarily when freq_table was never allocated.

This resolves a Smatch warning:
calling kfree() when 'dfc->freq_table' is always NULL.

---
 drivers/thermal/devfreq_cooling.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/devfreq_cooling.c +2 -1
index 597e86d16a4e..1c7dffc8d45f 100644
@@ -472,7 +472,8 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
 remove_qos_req:
 	dev_pm_qos_remove_request(&dfc->req_max_freq);
 free_table:
-	kfree(dfc->freq_table);
+	if (!dfc->em_pd)
+		kfree(dfc->freq_table);
 free_dfc:
 	kfree(dfc);
 
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Anas Iqbal

dfc->freq_table is only allocated in the non-EM path via devfreq_cooling_gen_tables(). In the EM path, it remains NULL.

Avoid calling kfree() unnecessarily when freq_table was never allocated.

This resolves a Smatch warning:
calling kfree() when 'dfc->freq_table' is always NULL.

---
  drivers/thermal/devfreq_cooling.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/devfreq_cooling.c +0 -0
index 597e86d16a4e..1c7dffc8d45f 100644

drivers/thermal/devfreq_cooling.c of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, · line 479

Quoted 9 lines
drivers/thermal/devfreq_cooling.c +2 -1
@@ -472,7 +472,8 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
  remove_qos_req:
  	dev_pm_qos_remove_request(&dfc->req_max_freq);
  free_table:
-	kfree(dfc->freq_table);
+	if (!dfc->em_pd)
+		kfree(dfc->freq_table);
  free_dfc:
  	kfree(dfc);
 

LGTM, let's calm down that warning.

maintainer Applied
#2 lore raw
Quoted 34 lines · Lukasz Luba
Quoted 18 lines · Anas Iqbal

dfc->freq_table is only allocated in the non-EM path via devfreq_cooling_gen_tables(). In the EM path, it remains NULL.

Avoid calling kfree() unnecessarily when freq_table was never allocated.

This resolves a Smatch warning:
calling kfree() when 'dfc->freq_table' is always NULL.

---
  drivers/thermal/devfreq_cooling.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/devfreq_cooling.c +0 -0
index 597e86d16a4e..1c7dffc8d45f 100644

drivers/thermal/devfreq_cooling.c of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, · line 479

Quoted 9 lines
drivers/thermal/devfreq_cooling.c +2 -1
@@ -472,7 +472,8 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
  remove_qos_req:
      dev_pm_qos_remove_request(&dfc->req_max_freq);
  free_table:
-     kfree(dfc->freq_table);
+     if (!dfc->em_pd)
+             kfree(dfc->freq_table);
  free_dfc:
      kfree(dfc);
 

LGTM, let's calm down that warning.

Quoted 1 line

Applied as 7.1 material, thanks!