From: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
To: David Laight
<David.Laight-ZS65k/vG3HxXrIkS9f7CXA@public.gmane.org>,
"Jason A. Donenfeld"
<Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>,
"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: "linux-fbdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-fbdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
<dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
"linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org"
<linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org>,
"linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org"
<linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
"linux-stm32-XDFAJ8BFU24N7RejjzZ/Li2xQDfSxrLKVpNB7YpNyf8@public.gmane.org"
<linux-stm32-XDFAJ8BFU24N7RejjzZ/Li2xQDfSxrLKVpNB7YpNyf8@public.gmane.org>,
"drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org"
<drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org>,
"dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org"
<dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org>,
"rds-devel-N0ozoZBvEnrZJqsBc5GL+g@public.gmane.org"
<rds-devel-N0ozoZBvEnrZJqsBc5GL+g@public.gmane.org>,
"linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"dccp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<dccp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible
Date: Wed, 12 Oct 2022 18:37:11 -0700 [thread overview]
Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> (raw)
In-Reply-To: <d45bd258e033453b85a137112e7694e1-1XygrNkDbNvwg4NCKwmqgw@public.gmane.org>
On Wed, 2022-10-12 at 21:29 +0000, David Laight wrote:
> From: Joe Perches
> > Sent: 12 October 2022 20:17
> >
> > On Wed, 2022-10-05 at 23:48 +0200, Jason A. Donenfeld wrote:
> > > The prandom_u32() function has been a deprecated inline wrapper around
> > > get_random_u32() for several releases now, and compiles down to the
> > > exact same code. Replace the deprecated wrapper with a direct call to
> > > the real function.
> > []
> > > diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
> > []
> > > @@ -734,7 +734,7 @@ static int send_connect(struct c4iw_ep *ep)
> > > &ep->com.remote_addr;
> > > int ret;
> > > enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
> > > - u32 isn = (prandom_u32() & ~7UL) - 1;
> > > + u32 isn = (get_random_u32() & ~7UL) - 1;
> >
> > trivia:
> >
> > There are somewhat odd size mismatches here.
> >
> > I had to think a tiny bit if random() returned a value from 0 to 7
> > and was promoted to a 64 bit value then truncated to 32 bit.
> >
> > Perhaps these would be clearer as ~7U and not ~7UL
>
> That makes no difference - the compiler will generate the same code.
True, more or less. It's more a question for the reader.
> The real question is WTF is the code doing?
True.
> The '& ~7u' clears the bottom 3 bits.
> The '- 1' then sets the bottom 3 bits and decrements the
> (random) high bits.
Right.
> So is the same as get_random_u32() | 7.
True, it's effectively the same as the upper 29 bits are random
anyway and the bottom 3 bits are always set.
> But I bet the coder had something else in mind.
Likely.
And it was also likely copy/pasted a few times.
next prev parent reply other threads:[~2022-10-13 1:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 21:48 [PATCH v1 0/5] treewide cleanup of random integer usage Jason A. Donenfeld via dev
2022-10-05 21:48 ` [PATCH v1 1/5] treewide: use prandom_u32_max() when possible Jason A. Donenfeld via Linux-f2fs-devel
[not found] ` <20221005214844.2699-2-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06 4:16 ` Kees Cook
2022-10-06 4:22 ` KP Singh
2022-10-06 12:45 ` Jason A. Donenfeld via dev
2022-10-06 12:55 ` Jason Gunthorpe
2022-10-06 13:05 ` Andy Shevchenko
2022-10-05 21:48 ` [PATCH v1 3/5] treewide: use get_random_u32() " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 8:43 ` Jan Kara
2022-10-06 12:33 ` [f2fs-dev] " Jason A. Donenfeld via dev
2022-10-06 13:01 ` Andy Shevchenko
2022-10-06 13:07 ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 12:47 ` Jason Gunthorpe
[not found] ` <Yz7OdfKZeGkpZSKb-uk2M96/98Pc@public.gmane.org>
2022-10-06 13:05 ` Jason A. Donenfeld via dev
2022-10-06 13:15 ` Jason Gunthorpe
2022-10-06 13:20 ` Andy Shevchenko
2022-10-12 19:16 ` Joe Perches
[not found] ` <20221005214844.2699-4-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-12 19:16 ` Joe Perches
[not found] ` <f8ad3ba44d28dec1a5f7626b82c5e9c2aeefa729.camel@perches.com>
[not found] ` <f8ad3ba44d28dec1a5f7626b82c5e9c2aeefa729.camel-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
2022-10-12 21:29 ` David Laight
[not found] ` <d45bd258e033453b85a137112e7694e1-1XygrNkDbNvwg4NCKwmqgw@public.gmane.org>
2022-10-13 1:37 ` Joe Perches [this message]
2022-10-05 21:48 ` [PATCH v1 4/5] treewide: use get_random_bytes " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 4:45 ` Kees Cook
[not found] ` <20221005214844.2699-5-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06 4:48 ` Kees Cook
[not found] ` <20221005214844.2699-1-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-05 21:48 ` [PATCH v1 2/5] treewide: use get_random_{u8, u16}() " Jason A. Donenfeld via dev
[not found] ` <20221005214844.2699-3-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06 4:38 ` Kees Cook
2022-10-06 12:28 ` Jason A. Donenfeld via dev
2022-10-05 21:48 ` [PATCH v1 5/5] prandom: remove unused functions Jason A. Donenfeld via dev
[not found] ` <20221005214844.2699-6-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06 4:39 ` Kees Cook
2022-10-06 4:55 ` [PATCH v1 0/5] treewide cleanup of random integer usage Kees Cook
2022-10-06 5:40 ` Kees Cook
2022-10-06 12:53 ` Jason A. Donenfeld via dev
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=3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com \
--to=joe-6d6dil74uinbdgjk7y7tuq@public.gmane.org \
--cc=David.Laight-ZS65k/vG3HxXrIkS9f7CXA@public.gmane.org \
--cc=Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org \
--cc=dccp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org \
--cc=drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-fbdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
--cc=linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-stm32-XDFAJ8BFU24N7RejjzZ/Li2xQDfSxrLKVpNB7YpNyf8@public.gmane.org \
--cc=rds-devel-N0ozoZBvEnrZJqsBc5GL+g@public.gmane.org \
--cc=target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).