On Fri, Aug 31, 2012 at 12:05 PM, Hongbo Zhang <hongbo.zh...@linaro.org> wrote:
>> > +/* Local function to create cpufreq clip table */
>> > +static int cpufreq_table_create(struct platform_device *pdev,
>> > +               struct freq_clip_table **freq_tab, int *num_freq)
>> > +{
>> > +       struct cpufreq_frequency_table *table;
>> > +       struct freq_clip_table *clip;
>> > +       unsigned int temp;
>> > +       int i, j, count = 0;
>> > +
>> > +       table = cpufreq_frequency_get_table(0);
>> > +       if (!table)
>> > +               return -ENODATA;
>> > +
>> > +       /* Check number of frequencies */
>> > +       for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
>>
>> unneeded () in the for condition
>>
>> > +               if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
>> > +                       continue;
>> > +               count++;
>> > +       }
>> > +
>> > +       clip = devm_kzalloc(&pdev->dev,
>> > +                       sizeof(struct freq_clip_table) * count,
>> > GFP_KERNEL);
>> > +
>> > +       /* Save frequencies */
>> > +       count = 0;
>> > +       for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
>> > +               if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
>> > +                       continue;
>> > +               clip[count].freq_clip_max = table[i].frequency;
>> > +               count++;
>> > +       }
>>
>> You are counting the frequencies twice: there is no need to re-set
>> count to 0 and re-increment it in the for loop.
>
>
> Francesco, thank you for all of your comments very much.
> The second count is used as index of array clip[], it is not redundant.
> If don't re-set it to 0, count-- should be used, so we set the array clip[]
> from the end, it seems a bit strange.

You are right, it's not redundant. Also, if the clip array is filled
from the end using --count, the information on the array size would be
lost, so this is not an option.

Francesco

_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to