From patchwork Mon Sep 3 21:40:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 965615 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=arista.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=arista.com header.i=@arista.com header.b="LmGOMTo4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4243LJ6xFLz9sBJ for ; Tue, 4 Sep 2018 07:40:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbeIDCC6 (ORCPT ); Mon, 3 Sep 2018 22:02:58 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:35114 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726008AbeIDCC6 (ORCPT ); Mon, 3 Sep 2018 22:02:58 -0400 Received: by mail-ed1-f67.google.com with SMTP id y20-v6so1718306edq.2 for ; Mon, 03 Sep 2018 14:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id; bh=oBNaecQNI5LUR61Xu70h7GexgqExlbs13fOtdKldeaU=; b=LmGOMTo45NB16Wuqs4wFEUWbj/XV6MvVyN8MtsHj6pJU/k81H6UX5oLhZ7em6d8DUq 8YYKXB6xVrpc2oDmRWwww/fuQePCQrIYDeT6Xy2kN5uJdoH/UL2gxzcwpHhDIumDJbAZ UW021s/AkSYY+6lSFjAWTBpmW7BtjlGiinbHwce9w2hPXtp0jjKS714Z7OzLzgrjmAMt Q8h67WpLc5d10ncsMrIjII0KTLjxFx8ZwmfQKTblXi7E9erXVYRPF6unwNy3SiXlKVbS cModMqTY4ZOahUJ7BzPytENKtBsZ/M0FlYejU+AmVt6vDFfGwyp4fglBawXD0hnNOUYb t3Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oBNaecQNI5LUR61Xu70h7GexgqExlbs13fOtdKldeaU=; b=dsUreOi3tHt1Tbo1rWp+PtG+dTWJayuXTy9SoPUk1u5dZhxAJPtg2VwnN080VjEmML P8y76LS9X2I96ejKbm7Su7ZHTgbsKtBhIclRlH7bBdf0PrXZ0uREXh2xxm9A7U+Lbsia XDIl8/7I8KDabcl3hTplH2aLIjqMaqNDwqvX1gcfp5v+5/VCaoisfjVtlPgHtYMxsiuQ 06RloR+g/5xjwCA29N7zx3KyPsgY2sMXL9WnXEPXbrbLed4Aw08U4fSU76WXY20gJbYc 61cv1nrEFqhHvZUErG/CujgHVHSIPp1cVfKqRDeoP8go+31UQ4+gwjWju4z0IkU+S1En LMOQ== X-Gm-Message-State: APzg51BgC5rIWaN3Ei6GqGo281McEwrtAobgdqsbzrZv4ePvD9m3JNqp qVvdzDieRXVCnYbeLXnXkr0n4w== X-Google-Smtp-Source: ANB0VdbDvQarCt9GGU6amhbV3wLmRNHcKEr1TBz2jj4r3dBWncs3iHnU69aqEJmRt5zek15qiOUU5g== X-Received: by 2002:a50:898b:: with SMTP id g11-v6mr32460973edg.82.1536010853046; Mon, 03 Sep 2018 14:40:53 -0700 (PDT) Received: from dhcp.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id x44-v6sm8430679edd.1.2018.09.03.14.40.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 14:40:52 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , Linus Torvalds , "David S. Miller" , Herbert Xu , Steffen Klassert , netdev@vger.kernel.org Subject: [PATCH] netlink: Make groups check less stupid in netlink_bind() Date: Mon, 3 Sep 2018 22:40:51 +0100 Message-Id: <20180903214051.4433-1-dima@arista.com> X-Mailer: git-send-email 2.13.6 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- net/netlink/af_netlink.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 930d17fa906c..b4a29bcc33b9 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -993,7 +993,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, struct netlink_sock *nlk = nlk_sk(sk); struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; int err = 0; - long unsigned int groups = nladdr->nl_groups; + unsigned long groups = nladdr->nl_groups; bool bound; if (addr_len < sizeof(struct sockaddr_nl)) @@ -1011,9 +1011,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, return err; } - if (nlk->ngroups == 0) - groups = 0; - else if (nlk->ngroups < 8*sizeof(groups)) + if (nlk->ngroups < BITS_PER_LONG) groups &= (1UL << nlk->ngroups) - 1; bound = nlk->bound;