Re: [PATCH V6 02/15] cpufreq: Add cpufreq_table_len()

From: Greg KH
Date: Wed Jan 08 2025 - 06:51:00 EST


On Wed, Jan 08, 2025 at 04:42:53PM +0530, Viresh Kumar wrote:
> On 07-01-25, 12:59, Greg KH wrote:
> > On Tue, Jan 07, 2025 at 04:51:35PM +0530, Viresh Kumar wrote:
> > > Add a function to calculate number of entries in the cpufreq table. This
> > > will be used by the Rust implementation.
> >
> > Again, why is Rust unique here? Why wouldn't the C code also need this?
>
> How about this:
>
> cpufreq: Add cpufreq_table_len()
>
> The last entry of a cpufreq table is marked by setting the frequency
> field to a special value: CPUFREQ_TABLE_END. The C code manages to
> traverse the table by checking the frequency field, until it reaches
> CPUFREQ_TABLE_END.
>
> The Rust cpufreq bindings though will need to know the length of the
> cpufreq table in advance, for example to check against an invalid index
> value.
>
> Provide a helper to calculate number of entries in the cpufreq table.
> will be used by the Rust implementation.

Odd, why can't Rust also know where CPUFREQ_TABLE_END is? Why do you
have to do extra work here? That feels wrong.

thanks,

greg k-h