Re: 回复: [PATCH v1] drivers:base:Fix unsigned compared with less than zero

From: Sudeep Holla
Date: Fri Jun 16 2023 - 05:01:59 EST


On Thu, Jun 15, 2023 at 07:50:45AM +0100, Conor Dooley wrote:
> Hey,
>
> For some (probably good) reason, this doesn't appear to have made it to
> the lists.
>
> On Thu, Jun 15, 2023 at 02:05:18AM +0000, 王明-软件底层技术部 wrote:
> > 发件人: Conor Dooley <conor@xxxxxxxxxx>
> > > On Wed, Jun 14, 2023 at 09:35:36PM +0800, Wang Ming wrote:
> > > > The return value of the of_count_cache_leaves() is long.
> > > > However, the return value is being assigned to an unsigned long
> > > > variable 'leaves',so making 'leaves' to long.
> > >
> > > But you actually made it an int?
> > >
> > > > silence the warning:
> > > > ./drivers/base/cacheinfo.c:300:5-11: WARNING: Unsigned expression
> > > > compared with zero: leaves > 0
> > >
> > > I'm dumb, why is comparing an unsigned value with zero a problem in
> > > and of itself? Zero is a valid value for an unsigned type, no?
> > >
> > > If you actually look at the function, it only returns positive,
> > > non-zero values anyway, so returning an int is a bit pointless, as
> > > are the checks, no?
>
> > Thank you, I see. This doesn't need to be fixed.
>
> Right, but I was suggesting that you should change the function to not
> return a signed value anymore & remove the check for whether it is
> zero, instead of your patch.
>
> Cheers,
> Conor.
>
> +CC Sudeep, Pierre: FYI. Original posting is at
> https://lore.kernel.org/all/20230614133549.3774-1-machel@xxxxxxxx/
> in case threading is broken, as I think the in-reply-to header in what
> I am replying to is corrupted.

Also if the original thread landed, I couldn't have responded because of
the disclaimer 🙁.

--
Regards,
Sudeep