[U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

Renato Andreola
2009-08-07T12:14:06Z

Ok, for the change.
What is the preferred way to proceed? have I got to resubmit a patch for
the change with the DIV_ROUND_UP macro?

Best regards,
Renato Andreola

Wolfgang Denk wrote:
> Dear Renato Andreola,
>
> In message <4A7BE28A.8080701@imagos.it> you wrote:
>
>> I'd like to clarify what is the problem with the timeout and the Intel
>> flash (even if the following comments can be obvious or already well
>> known) and to ask you an opinion on a small code change.
>>
>
> Thanks.
>
> ...
>
>> I think that an expression like this
>>
>> #if CONFIG_SYS_HZ != 1000
>> if ((ulong)CONFIG_SYS_HZ > 10000)
>> tout *= ((ulong)CONFIG_SYS_HZ)/1000; /* for a big HZ, avoid
>> overflow */
>> else
>> tout = (tout * (ulong)CONFIG_SYS_HZ + 500) / 1000;
>> #endif
>>
>> could be better because
>> - it forces the data type of the system dependent CONFIG_SYS_HZ value to
>> ulong (no float!)
>> - it rounds tout to 0.5 timer tick and leaves tout unchanged if
>> CONFIG_SYS_HZ == 1000
>>
>> What do you think about?
>>
>
> I'd prefer "tout = DIV_ROUND_UP(tout*CONFIG_SYS_HZ, 1000);"
>
>
> Best regards,
>
> Wolfgang Denk
>
>