[PATCH] thermal: devfreq_cooling: avoid unnecessary kfree of freq_table

Anas Iqbal posted 1 patch 1 week, 4 days ago
drivers/thermal/devfreq_cooling.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] thermal: devfreq_cooling: avoid unnecessary kfree of freq_table
Posted by Anas Iqbal 1 week, 4 days ago
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.

Signed-off-by: Anas Iqbal <mohd.abd.6602@gmail.com>
---
 drivers/thermal/devfreq_cooling.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
index 597e86d16a4e..1c7dffc8d45f 100644
--- a/drivers/thermal/devfreq_cooling.c
+++ b/drivers/thermal/devfreq_cooling.c
@@ -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);
 
-- 
2.43.0
Re: [PATCH] thermal: devfreq_cooling: avoid unnecessary kfree of freq_table
Posted by Lukasz Luba 1 week, 4 days ago

On 3/23/26 09:40, Anas Iqbal wrote:
> 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.
> 
> Signed-off-by: Anas Iqbal <mohd.abd.6602@gmail.com>
> ---
>   drivers/thermal/devfreq_cooling.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
> index 597e86d16a4e..1c7dffc8d45f 100644
> --- a/drivers/thermal/devfreq_cooling.c
> +++ b/drivers/thermal/devfreq_cooling.c
> @@ -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.

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Re: [PATCH] thermal: devfreq_cooling: avoid unnecessary kfree of freq_table
Posted by Rafael J. Wysocki 1 week, 4 days ago
On Mon, Mar 23, 2026 at 11:44 AM Lukasz Luba <lukasz.luba@arm.com> wrote:
>
>
>
> On 3/23/26 09:40, Anas Iqbal wrote:
> > 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.
> >
> > Signed-off-by: Anas Iqbal <mohd.abd.6602@gmail.com>
> > ---
> >   drivers/thermal/devfreq_cooling.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
> > index 597e86d16a4e..1c7dffc8d45f 100644
> > --- a/drivers/thermal/devfreq_cooling.c
> > +++ b/drivers/thermal/devfreq_cooling.c
> > @@ -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.
>
> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

Applied as 7.1 material, thanks!