[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <2b6eabad-ebd1-4e7d-b4bf-6b818dfc20ac@app.fastmail.com>
Date: Thu, 09 Jan 2025 07:29:01 +0100
From: "Arnd Bergmann" <arnd@...db.de>
To: "Hans Zhang" <18255117159@....com>, "Niklas Cassel" <cassel@...nel.org>
Cc: "Manivannan Sadhasivam" <manivannan.sadhasivam@...aro.org>,
Krzysztof WilczyĆski <kw@...ux.com>,
"Kishon Vijay Abraham I" <kishon@...nel.org>,
"Greg Kroah-Hartman" <gregkh@...uxfoundation.org>, linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org, rockswang7@...il.com
Subject: Re: [v8] misc: pci_endpoint_test: Fix overflow of bar_size
On Thu, Jan 9, 2025, at 03:59, Hans Zhang 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
Powered by blists - more mailing lists