From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by mail19.linbit.com (LINBIT Mail Daemon) with ESMTP id C9210420372 for ; Wed, 12 Oct 2022 23:35:12 +0200 (CEST) From: David Laight To: 'Joe Perches' , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" Date: Wed, 12 Oct 2022 21:29:02 +0000 Message-ID: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> In-Reply-To: MIME-Version: 1.0 Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "linux-fbdev@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-mmc@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linux-mm@kvack.org" , "linux-sctp@vger.kernel.org" , "target-devel@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "linux-stm32@st-md-mailman.stormreply.com" , "drbd-dev@lists.linbit.com" , "dev@openvswitch.org" , "rds-devel@oss.oracle.com" , "linux-scsi@vger.kernel.org" , "dccp@vger.kernel.org" , "linux-rdma@vger.kernel.org" , "kasan-dev@googlegroups.com" , "lvs-devel@vger.kernel.org" , "coreteam@netfilter.org" , "netfilter-devel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , "linux-media@vger.kernel.org" , "linux-actions@lists.infradead.org" , "brcm80211-dev-list.pdl@broadcom.com" , "linux-block@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-nvme@lists.infradead.org" , "linux-hams@vger.kernel.org" , "ceph-devel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "cake@lists.bufferbloat.net" , "linux-nfs@vger.kernel.org" , "linux-raid@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-wireless@vger.kernel.org" , "SHA-cyfmac-dev-list@infineon.com" , "linux-f2fs-devel@lists.sourceforge.net" , "linux-xfs@vger.kernel.org" , "tipc-discussion@lists.sourceforge.net" , "linux-crypto@vger.kernel.org" , "dmaengine@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" Subject: Re: [Drbd-dev] [PATCH v1 3/5] treewide: use get_random_u32() when possible List-Id: "*Coordination* of development, patches, contributions -- *Questions* \(even to developers\) go to drbd-user, please." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Joe Perches > Sent: 12 October 2022 20:17 >=20 > 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/c= xgb4/cm.c > [] > > @@ -734,7 +734,7 @@ static int send_connect(struct c4iw_ep *ep) > > =09=09=09=09 &ep->com.remote_addr; > > =09int ret; > > =09enum chip_type adapter_type =3D ep->com.dev->rdev.lldi.adapter_type= ; > > -=09u32 isn =3D (prandom_u32() & ~7UL) - 1; > > +=09u32 isn =3D (get_random_u32() & ~7UL) - 1; >=20 > trivia: >=20 > There are somewhat odd size mismatches here. >=20 > 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. >=20 > Perhaps these would be clearer as ~7U and not ~7UL That makes no difference - the compiler will generate the same code. The real question is WTF is the code doing? The '& ~7u' clears the bottom 3 bits. The '- 1' then sets the bottom 3 bits and decrements the (random) high bits. So is the same as get_random_u32() | 7. But I bet the coder had something else in mind. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)