Re: [PATCH v2] cpupower: fix use-after-free and stale limits in frequency-set
From: Lukas Beckmann
Date: Tue Nov 17 2026 - 11:12:02 EST
On Mon, Nov 16, 2026 at 04:30:10PM -0700, Shuah Khan wrote:
> On 11/15/26 03:03, Lukas Beckmann wrote:
> > @@ -141,9 +141,10 @@ static unsigned long string_to_frequency(const char *str)
> > }
> > }
> > -static int do_new_policy(unsigned int cpu, struct cpufreq_policy *new_pol)
> > +static int do_new_policy(unsigned int cpu, const struct cpufreq_policy *new_pol)
> > {
> > struct cpufreq_policy *cur_pol = cpufreq_get_policy(cpu);
> > + struct cpufreq_policy temp_pol;
> > int ret;
> > if (!cur_pol) {
> > @@ -151,16 +152,22 @@ static int do_new_policy(unsigned int cpu, struct cpufreq_policy *new_pol)
> > return -EINVAL;
> > }
> > - if (!new_pol->min)
> > - new_pol->min = cur_pol->min;
>
> Why can't you leave this logic as is and set temp_pol fieds,
> if (!new_pol->min)
> temp_pol = cur_pol->min;
> else
> temp_pol.min = new_pol->min;
[...]
>
> Same for all of the above. Make just the minimum changes
> to fix the problem instead of changing the logic
>
I did it this way because I found it easier to read. I will keep the
original conditions in V3 to keep the diff smaller.
Thanks,
Lukas