Re: [PATCH] cpufreq: powernv: Check negative value returned by cpufreq_table_find_index_dl()
From: Viresh Kumar
Date: Wed Feb 21 2018 - 00:55:01 EST
On 21-02-18, 16:39, Michael Ellerman wrote:
> Viresh Kumar <viresh.kumar@xxxxxxxxxx> writes:
> > AFAICT, you will get -1 here only if the freq table had no valid
> > frequencies (or the freq table is empty). Why would that happen ?
>
> Bugs?
The cupfreq driver shouldn't have registered itself in that case (i.e.
if the cpufreq table is empty).
> Or if you ask for a target_freq that is higher than anything in the
> table.
You will still get a valid index in that case.
There is only once case where we return -1, when the cpufreq table
doesn't have any valid frequencies.
> Or the API changes, and we forget to update this call site.
I am not sure we can do much about that right now.
> If you're saying that cpufreq_table_find_index_dl() can NEVER fail,
Yes, if we have at least one valid frequency in the table, otherwise
the cpufreq driver shouldn't have registered itself.
> then
> write it so that it can never fail and change it to return unsigned int.
But what should we do when there is no frequency in the cpufreq table?
Just in case where a driver is buggy and tries to call this routine
for an invalid table.
> Having it potentially return -1, which is then used to index an array
> and not handling that is just asking for bugs to happen.
I understand what you are trying to say here, but I don't know what
can be done to prevent this here.
What we can do is change the return type to void and pass a int
pointer to the routine, but that wouldn't change anything at all. That
pointers variable can still have -1 in it.
--
viresh