From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Miller Subject: Re: [PATCH] netlink: Make groups check less stupid in netlink_bind() Date: Wed, 05 Sep 2018 22:11:56 -0700 (PDT) Message-ID: <20180905.221156.794134129220434079.davem@davemloft.net> References: <20180903214051.4433-1-dima@arista.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: linux-kernel@vger.kernel.org, 0x7f454c46@gmail.com, torvalds@linux-foundation.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, netdev@vger.kernel.org To: dima@arista.com Return-path: In-Reply-To: <20180903214051.4433-1-dima@arista.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org From: Dmitry Safonov Date: Mon, 3 Sep 2018 22:40:51 +0100 > As Linus noted, the test for 0 is needless, groups type can follow the > usual kernel style and 8*sizeof(unsigned long) is BITS_PER_LONG: > >> The code [..] isn't technically incorrect... >> But it is stupid. >> Why stupid? Because the test for 0 is pointless. >> >> Just doing >> if (nlk->ngroups < 8*sizeof(groups)) >> groups &= (1UL << nlk->ngroups) - 1; >> >> would have been fine and more understandable, since the "mask by shift >> count" already does the right thing for a ngroups value of 0. Now that >> test for zero makes me go "what's special about zero?". It turns out >> that the answer to that is "nothing". > [..] >> The type of "groups" is kind of silly too. >> >> Yeah, "long unsigned int" isn't _technically_ wrong. But we normally >> call that type "unsigned long". > > Cleanup my piece of pointlessness. > > Cc: "David S. Miller" > Cc: Herbert Xu > Cc: Steffen Klassert > Cc: netdev@vger.kernel.org > Fairly-blamed-by: Linus Torvalds > Signed-off-by: Dmitry Safonov Applied to net-next, thanks.