From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE400C433FE for ; Thu, 13 Oct 2022 01:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbiJMBnX convert rfc822-to-8bit (ORCPT ); Wed, 12 Oct 2022 21:43:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiJMBnV (ORCPT ); Wed, 12 Oct 2022 21:43:21 -0400 Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7678936DEB; Wed, 12 Oct 2022 18:43:19 -0700 (PDT) Received: from omf20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 640C9120237; Thu, 13 Oct 2022 01:37:28 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id 56EDD20026; Thu, 13 Oct 2022 01:37:01 +0000 (UTC) Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible From: Joe Perches To: David Laight , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" Cc: "linux-fbdev@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-wireless@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" , "SHA-cyfmac-dev-list@infineon.com" , "coreteam@netfilter.org" , "tipc-discussion@lists.sourceforge.net" , "linux-ext4@vger.kernel.org" , "linux-media@vger.kernel.org" , "linux-actions@lists.infradead.org" , "linux-nfs@vger.kernel.org" , "linux-block@vger.kernel.org" , "dmaengine@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" , "brcm80211-dev-list.pdl@broadcom.com" , "linux-raid@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-mmc@vger.kernel.org" , "linux-f2fs-devel@lists.sourceforge.net" , "linux-xfs@vger.kernel.org" , "netfilter-devel@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" Date: Wed, 12 Oct 2022 18:37:11 -0700 In-Reply-To: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: jmxt1u5agdpi9w76hr4tp6uotie3p373 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 56EDD20026 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18KEIRmyyr9pSEavQqF5X0dTzAEITyiJq4= X-HE-Tag: 1665625021-540494 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.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. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47AA3C4332F for ; Thu, 13 Oct 2022 01:37:43 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1oinAK-0004e2-RB; Thu, 13 Oct 2022 01:37:40 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oinAJ-0004do-I0; Thu, 13 Oct 2022 01:37:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Transfer-Encoding:Content-Type :References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=c2YwssGIaPysLPcR20mrskERCj5dzMDhD63/1J4p7RU=; b=PLPw745zS9uMBrf6r8+9n/G+hO 32zjVzM9tMfQ2RFI2bGyCMkUIxMxOrFtpzV1p5ZlGnk5LI2LQsAWcrAc18LF4PAldNv/KbOsV1VIy jrsvmmskWd4bSwSStQ1WDX3SdhMuMPLyk6s+J/oyV15h9bCx4gT8PlsS8svpUdM7m/Pk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Transfer-Encoding:Content-Type:References: In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=c2YwssGIaPysLPcR20mrskERCj5dzMDhD63/1J4p7RU=; b=fht1Aej5Gv8b7tF9obyuV/rNYY pqrr7s0JpWXIQFTh0WhjhSmaNhliQUhJXCJiefEtp9KirqcuABRaXex+PpM8oxcBqOXkPDwAkPhBF vMHP3bDYFnIq2MtM4ni9nIH4Yzgt1zI+gwvbfG4RIlufTu6tRzJsGpWS6/bqmRPglkw8=; Received: from smtprelay0013.hostedemail.com ([216.40.44.13] helo=relay.hostedemail.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1oinAH-0001pt-Ok; Thu, 13 Oct 2022 01:37:39 +0000 Received: from omf20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 640C9120237; Thu, 13 Oct 2022 01:37:28 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id 56EDD20026; Thu, 13 Oct 2022 01:37:01 +0000 (UTC) Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> From: Joe Perches To: David Laight , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" Date: Wed, 12 Oct 2022 18:37:11 -0700 In-Reply-To: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: jmxt1u5agdpi9w76hr4tp6uotie3p373 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 56EDD20026 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18KEIRmyyr9pSEavQqF5X0dTzAEITyiJq4= X-HE-Tag: 1665625021-540494 X-Headers-End: 1oinAH-0001pt-Ok Subject: Re: [f2fs-dev] [PATCH v1 3/5] treewide: use get_random_u32() when possible X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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" , "SHA-cyfmac-dev-list@infineon.com" , "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" , "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" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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. _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4032BC4332F for ; Thu, 13 Oct 2022 01:37:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B5B7210E393; Thu, 13 Oct 2022 01:37:36 +0000 (UTC) Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6EE2510E393 for ; Thu, 13 Oct 2022 01:37:33 +0000 (UTC) Received: from omf20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 640C9120237; Thu, 13 Oct 2022 01:37:28 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id 56EDD20026; Thu, 13 Oct 2022 01:37:01 +0000 (UTC) Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible From: Joe Perches To: David Laight , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" Date: Wed, 12 Oct 2022 18:37:11 -0700 In-Reply-To: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: jmxt1u5agdpi9w76hr4tp6uotie3p373 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 56EDD20026 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18KEIRmyyr9pSEavQqF5X0dTzAEITyiJq4= X-HE-Tag: 1665625021-540494 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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" , "SHA-cyfmac-dev-list@infineon.com" , "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" , "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" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, 2022-10-12 at 21:29 +0000, David Laight wrote: > 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 aroun= d > > > 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 =3D ep->com.dev->rdev.lldi.adapter_type= ; > > > - u32 isn =3D (prandom_u32() & ~7UL) - 1; > > > + u32 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 >=20 > 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E94BC4332F for ; Thu, 13 Oct 2022 01:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F/aJNN/BEkJ4vIKLoIFMnT/DE9iVW3BRakBWMddJJhE=; b=I4VVdLVoDpCdC9 g0eeNCJ8qhZm/+q2q8YaupCjHgMA4/R1JP8yW8TBQzKnI17arGzzeIqsy9cInbcdmvXuXL4dYkUcm AyPOQDQoZJloV9lWjBD22MWJetsrVptJ+sCC0zAKbB98w2TURa3/w86uK/Na51v02wj4SWxSBVeXC mV2ooSN0f46PCAXKTU93UsoJMiJdDxbkhVY+UNRz27zk+IiREQDnpVbnlM7c4J3Evk6eGZSwVfvum SKOHY9UP9iB7e3oZH7V8L5vWnXwSsNa7esGiFatq/4uD07Lux4mRjKxTd/h1pKlze583EDdCQKfgN 6v3F3QZDR+DgKgicrpeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oinAR-00AAG5-5M; Thu, 13 Oct 2022 01:37:47 +0000 Received: from smtprelay0017.hostedemail.com ([216.40.44.17] helo=relay.hostedemail.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oinAF-00AABl-BU; Thu, 13 Oct 2022 01:37:36 +0000 Received: from omf20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 640C9120237; Thu, 13 Oct 2022 01:37:28 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id 56EDD20026; Thu, 13 Oct 2022 01:37:01 +0000 (UTC) Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible From: Joe Perches To: David Laight , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" Cc: "linux-fbdev@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-wireless@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" , "SHA-cyfmac-dev-list@infineon.com" , "coreteam@netfilter.org" , "tipc-discussion@lists.sourceforge.net" , "linux-ext4@vger.kernel.org" , "linux-media@vger.kernel.org" , "linux-actions@lists.infradead.org" , "linux-nfs@vger.kernel.org" , "linux-block@vger.kernel.org" , "dmaengine@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" , "brcm80211-dev-list.pdl@broadcom.com" , "linux-raid@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-mmc@vger.kernel.org" , "linux-f2fs-devel@lists.sourceforge.net" , "linux-xfs@vger.kernel.org" , "netfilter-devel@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" Date: Wed, 12 Oct 2022 18:37:11 -0700 In-Reply-To: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: jmxt1u5agdpi9w76hr4tp6uotie3p373 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 56EDD20026 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18KEIRmyyr9pSEavQqF5X0dTzAEITyiJq4= X-HE-Tag: 1665625021-540494 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221012_183735_470686_58769CF7 X-CRM114-Status: GOOD ( 19.42 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.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. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84B85C433FE for ; Thu, 13 Oct 2022 01:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MdDVrfJDsCyCgqN7O+KayCixqS7FBaVpezWX1OOjDWw=; b=lWDTqV+xj/W0ak ZrZQgdEjyvcn0312rl4lXngSlmAiZAj5YisD41qoAdIK2bWwjPFOK/of7PUOMPWP+B/1UKE82tCZG 3mVvWypPZ2L4JPQgL/LGQG6qbYXGCgDLz6ae5cGwNFPlspzBHuPGaqz0vZviDuoUvr0eGj/iZqQ5/ EvzXE1ellalaBKDy1h+xy236ys8z8EzWn5yngyYWvH8B8uxm7sbXrfwqdx5Wd9yZZ0ut/On8lnIVv hjP/hfrvbZu1x52bAIob4QSL3OBeF6swAKCE6nMKZ7iyy62ltTAf9HIbWvK0fOC23vp+LxF/pGwsn QBJmAYXCZocxJ1xlcavA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oinAI-00AADr-Hq; Thu, 13 Oct 2022 01:37:38 +0000 Received: from smtprelay0017.hostedemail.com ([216.40.44.17] helo=relay.hostedemail.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oinAF-00AABl-BU; Thu, 13 Oct 2022 01:37:36 +0000 Received: from omf20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 640C9120237; Thu, 13 Oct 2022 01:37:28 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id 56EDD20026; Thu, 13 Oct 2022 01:37:01 +0000 (UTC) Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible From: Joe Perches To: David Laight , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" Cc: "linux-fbdev@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-wireless@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" , "SHA-cyfmac-dev-list@infineon.com" , "coreteam@netfilter.org" , "tipc-discussion@lists.sourceforge.net" , "linux-ext4@vger.kernel.org" , "linux-media@vger.kernel.org" , "linux-actions@lists.infradead.org" , "linux-nfs@vger.kernel.org" , "linux-block@vger.kernel.org" , "dmaengine@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" , "brcm80211-dev-list.pdl@broadcom.com" , "linux-raid@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-mmc@vger.kernel.org" , "linux-f2fs-devel@lists.sourceforge.net" , "linux-xfs@vger.kernel.org" , "netfilter-devel@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" Date: Wed, 12 Oct 2022 18:37:11 -0700 In-Reply-To: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: jmxt1u5agdpi9w76hr4tp6uotie3p373 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 56EDD20026 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18KEIRmyyr9pSEavQqF5X0dTzAEITyiJq4= X-HE-Tag: 1665625021-540494 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221012_183735_470686_58769CF7 X-CRM114-Status: GOOD ( 19.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 294C2C4332F for ; Thu, 13 Oct 2022 01:38:13 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Mnsbl3CmBz3dwV for ; Thu, 13 Oct 2022 12:38:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.helo=relay.hostedemail.com (client-ip=216.40.44.17; helo=relay.hostedemail.com; envelope-from=joe@perches.com; receiver=) Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Mnsb63XVFz2yxc for ; Thu, 13 Oct 2022 12:37:36 +1100 (AEDT) Received: from omf20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 640C9120237; Thu, 13 Oct 2022 01:37:28 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id 56EDD20026; Thu, 13 Oct 2022 01:37:01 +0000 (UTC) Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible From: Joe Perches To: David Laight , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" Date: Wed, 12 Oct 2022 18:37:11 -0700 In-Reply-To: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: jmxt1u5agdpi9w76hr4tp6uotie3p373 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 56EDD20026 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18KEIRmyyr9pSEavQqF5X0dTzAEITyiJq4= X-HE-Tag: 1665625021-540494 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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" , "SHA-cyfmac-dev-list@infineon.com" , "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.o rg" , "netdev@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-wireless@vger.kernel.org" , "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" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Wed, 2022-10-12 at 21:29 +0000, David Laight wrote: > 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 aroun= d > > > 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 =3D ep->com.dev->rdev.lldi.adapter_type= ; > > > - u32 isn =3D (prandom_u32() & ~7UL) - 1; > > > + u32 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 >=20 > 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. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Date: Thu, 13 Oct 2022 01:37:11 +0000 Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible Message-Id: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: dccp@vger.kernel.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. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible Date: Wed, 12 Oct 2022 18:37:11 -0700 Message-ID: <3f527ec95a12135eb40f5f2d156a2954feb7fbfe.camel@perches.com> References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: drbd-dev-bounces-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org Errors-To: drbd-dev-bounces-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org To: David Laight , "Jason A. Donenfeld" , "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" Cc: "linux-fbdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org" , "linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org" , "linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org" , "linux-stm32-XDFAJ8BFU24N7RejjzZ/Li2xQDfSxrLKVpNB7YpNyf8@public.gmane.org" , "drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org" , "dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org" , "rds-devel-N0ozoZBvEnrZJqsBc5GL+g@public.gmane.org" , "linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "dccp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "linux-rdma-u79uwXL29TY76Z2rM5mHXA@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.