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

From: Rafael J. Wysocki

Date: Mon Mar 23 2026 - 10:00:18 EST


On Mon, Mar 23, 2026 at 11:44 AM Lukasz Luba <lukasz.luba@xxxxxxx> 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@xxxxxxxxx>
> > ---
> > 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@xxxxxxx>

Applied as 7.1 material, thanks!