From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: "Jason A. Donenfeld" <zx2c4@kernel.org>,
"kbuild-all@lists.01.org" <kbuild-all@lists.01.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [crng-random:jd/get_random_u32_below 23/23] include/linux/random.h:64:69: sparse: sparse: cast truncates bits from constant value (1f4 becomes f4)
Date: Tue, 11 Oct 2022 17:31:02 -0600 [thread overview]
Message-ID: <Y0X8tuJjEfR48xiD@zx2c4.com> (raw)
In-Reply-To: <4bbbde65cef74a579de34a75e6dba0a3@AcuMS.aculab.com>
On Tue, Oct 11, 2022 at 11:24:50PM +0000, David Laight wrote:
> From: Jason A. Donenfeld
> > Sent: 10 October 2022 18:54
> >
> > On Mon, Oct 10, 2022 at 05:18:40PM +0000, David Laight wrote:
> > > From: kernel test robot <lkp@intel.com>
> > > > Sent: 10 October 2022 00:32
> > > > To: Jason A. Donenfeld <zx2c4@kernel.org>
> > > ...
> > >
> > > I'm missing the main mailing list email for this change.
> > > I'm guessing the non-inlined code for non-constant ceil
> > > is similar.
> >
> > It's part of a development tree I already linked you to. It's not done
> > yet. This alert is just about needing a __force.
>
> I keep thinking about this one.
> sparse is being stupid because it is looking at code that cade be reached.
> 'ceil' must be 500 so the test at line 62 is false.
> But what is the cast for?
> Line 64 is only executed when ceil is <= 256 and the condition
> only matters when ceil <= 255 - so the cast cannot be needed.
Yes, it's sparse being stupid.
> I think you might be trying to do 8-bit arithmetic - but you
> should know it gets promoted to 'int' (and then to unsigned int).
> What might do what you intended is (u8)~ceil % ceil.
> But that is the same as (0xff - ceil) % ceil.
Right. This already came up in a different thread and I made that change
already.
> Which is the same as 0xff % ceil.
Same as 0x100 % ceil, rather. It's compile-time evaluation though, keep
in mind, so it doesn't matter.
> A quick check with ceil == 5 gives the wrong answer
> as all values get accepted - and one need to be excluded.
> So you either need (mult & 0xff) > 0xff % ceil
> or (mult & 0xff) >= 0x100 % ceil.
Yes.
Jason
prev parent reply other threads:[~2022-10-11 23:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-09 23:32 [crng-random:jd/get_random_u32_below 23/23] include/linux/random.h:64:69: sparse: sparse: cast truncates bits from constant value (1f4 becomes f4) kernel test robot
2022-10-10 17:18 ` David Laight
2022-10-10 17:53 ` Jason A. Donenfeld
2022-10-11 23:24 ` David Laight
2022-10-11 23:31 ` Jason A. Donenfeld [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y0X8tuJjEfR48xiD@zx2c4.com \
--to=jason@zx2c4.com \
--cc=David.Laight@ACULAB.COM \
--cc=kbuild-all@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zx2c4@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox