Re: [v8] misc: pci_endpoint_test: Fix overflow of bar_size

Hans Zhang
2025-01-09T09:19:56Z

On 2025/1/9 14:29, Arnd Bergmann wrote:
>> On 2025/1/8 22:13, Niklas Cassel wrote:
>>>>> Ok. Looking at do_div(), it seems to be the correct API to use
>>>>> for this problem. Just change bar_size type to u64 (instead of casting)
>>>>> and use do_div() ? That is how it is seems to be used in other drivers.
>>>>
>>>> I think using div_u64_rem() instead of do_div() would make this
>>>> more readable as this is always an inline function, so the type can
>>>> remain resource_size_t, and the division gets optimized well when
>>>> that is a 32-bit type.
>>>
>>> After patch 1/2, we no longer care about the remainder, so I guess
>>> div64_u64() is the correct function to use then?
>
> div_u64() is the correct interface here, div64_u64() is the
> even slower version where both arguments are 64-bit wide.
>
>> >> drivers/misc/pci_endpoint_test.c:311:11: warning: comparison of
>> distinct pointer types ('typeof ((bar_size)) *' (aka 'unsigned int *')
>> and 'uint64_t *' (aka 'unsigned long long *'))
>> [-Wcompare-distinct-pointer-types]
>> 311 | remain = do_div(bar_size, buf_size);
>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~
>
> You don't use div_u64() or div64_u64() here, do_div() is the macro
> version that must be called with a 64-bit argument.
>
> Arnd

Thank you so much Niklas and Arnd.

Best regards
Hans