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