Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible

From
Jason A. Donenfeld <Jason@zx2c4.com>
Date
2022-10-06 15:03:08
Also in
dri-devel, linux-f2fs-devel, linux-hams, linux-nvme, lvs-devel
Reply to
Jason Gunthorpe, 2022-10-06
On Thu, Oct 6, 2022 at 6:47 AM Jason Gunthorpe [off-list ref] wrote:
On Wed, Oct 05, 2022 at 11:48:42PM +0200, Jason A. Donenfeld wrote:
quoted
index 14392c942f49..499a425a3379 100644
--- 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;
Maybe this wants to be written as

(prandom_max(U32_MAX >> 7) << 7) | 7

?
Holy smokes. Yea I guess maybe? It doesn't exactly gain anything or
make the code clearer though, and is a little bit more magical than
I'd like on a first pass.
quoted
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.

Jason
Thread (31 messages) 31 messages, 8 authors, last reply 2022-10-13
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help