Re: [PATCH V2 2/2] cpufreq: Add Loongson-3 CPUFreq driver support

From: Huacai Chen
Date: Thu Jul 04 2024 - 03:37:46 EST


On Thu, Jul 4, 2024 at 11:15 AM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
>
> On 03-07-24, 22:37, Huacai Chen wrote:
> > On Wed, Jul 3, 2024 at 6:18 PM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
> > > > +static int loongson3_cpufreq_target(struct cpufreq_policy *policy, unsigned int index)
> > > > +{
> > > > + /* setting the cpu frequency */
> > > > + return loongson3_cpufreq_set(policy, index);
> > >
> > > Why use a separate function for calling do_service_request() ? Just
> > > open code it here.
> > Hmm, there is a loongson3_cpufreq_get() function, so I make a
> > loongson3_cpufreq_set() function, too.
>
> The counterpart of _get is _target and so a separate set function
> isn't required at all. Just get rid of it.
OK, will do.

>
> > > > +static int loongson3_cpufreq_get_freq_table(int cpu)
> > > > +{
> > > > + int i, ret, boost_level, max_level, freq_level;
> > > > + struct cpufreq_frequency_table *table;
> > > > +
> > > > + if (per_cpu(freq_table, cpu))
> > > > + return 0;
> > > > +
> > > > + ret = do_service_request(cpu, 0, CMD_GET_FREQ_LEVEL_NUM, 0, 0);
> > > > + if (ret < 0)
> > > > + return ret;
> > > > + max_level = ret;
> > > > +
> > > > + ret = do_service_request(cpu, 0, CMD_GET_FREQ_BOOST_LEVEL, 0, 0);
> > > > + if (ret < 0)
> > > > + return ret;
> > > > + boost_level = ret;
> > > > +
> > > > + freq_level = min(max_level, FREQ_MAX_LEVEL);
> > > > + table = kzalloc(sizeof(struct cpufreq_frequency_table) * (freq_level + 1), GFP_KERNEL);
> > >
> > > devm_kcalloc(pdev, ...) instead ?
> > I remember you told me this in V1, but devm_kalloc() needs a pdev
> > instance, which doesn't exist here, so I keep kzalloc().
>
> See how drivers/cpufreq/brcmstb-avs-cpufreq.c stores the pdev in
> cpufreq_driver's driver_data and reuses later on.
OK, I have learned that devm_kzalloc() allocated memory will be
automatically freed at driver dettach.
But I have another question: can the "kfree(table)" after
do_service_request() fail be removed? Because I think in this case
the probe will fail, then no driver detach happens.

Huacai

>
> --
> viresh