Message ID | 20221005214844.2699-1-Jason@zx2c4.com |
---|---|
Headers | show |
Series | treewide cleanup of random integer usage | expand |
On Thu, Oct 06, 2022 at 06:33:15AM -0600, Jason A. Donenfeld wrote: > On Thu, Oct 06, 2022 at 10:43:31AM +0200, Jan Kara wrote: ... > > The code here is effectively doing the > > > > parent_group = prandom_u32_max(ngroups); > > > > Similarly here we can use prandom_u32_max(ngroups) like: > > > > if (qstr) { > > ... > > parent_group = hinfo.hash % ngroups; > > } else > > parent_group = prandom_u32_max(ngroups); > > Nice catch. I'll move these to patch #1. I believe coccinelle is able to handle this kind of code as well, so Kees' proposal to use it seems more plausible since it's less error prone and more flexible / powerful.
On Thu, Oct 6, 2022 at 7:01 AM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Thu, Oct 06, 2022 at 06:33:15AM -0600, Jason A. Donenfeld wrote: > > On Thu, Oct 06, 2022 at 10:43:31AM +0200, Jan Kara wrote: > > ... > > > > The code here is effectively doing the > > > > > > parent_group = prandom_u32_max(ngroups); > > > > > > Similarly here we can use prandom_u32_max(ngroups) like: > > > > > > if (qstr) { > > > ... > > > parent_group = hinfo.hash % ngroups; > > > } else > > > parent_group = prandom_u32_max(ngroups); > > > > Nice catch. I'll move these to patch #1. > > I believe coccinelle is able to handle this kind of code as well I'd be extremely surprised. The details were kind of non obvious. I just spent a decent amount of time manually checking those blocks, to make sure we didn't wind up with different behavior, given the variable reuse. Jason
On Thu, Oct 06, 2022 at 07:05:48AM -0600, Jason A. Donenfeld wrote: > > > diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c > > > index fd9d7f2c4d64..a605cf66b83e 100644 > > > --- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c > > > +++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c > > > @@ -465,7 +465,7 @@ static int ipoib_cm_req_handler(struct ib_cm_id *cm_id, > > > goto err_qp; > > > } > > > > > > - psn = prandom_u32() & 0xffffff; > > > + psn = get_random_u32() & 0xffffff; > > > > prandom_max(0xffffff + 1) > > That'd work, but again it's not more clear. Authors here are going for > a 24-bit number, and masking seems like a clear way to express that. vs just asking directly for a 24 bit number? Jason