All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netlink: Make groups check less stupid in netlink_bind()
@ 2018-09-03 21:40 Dmitry Safonov
  2018-09-06  5:11 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Safonov @ 2018-09-03 21:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Dmitry Safonov, Dmitry Safonov, Linus Torvalds, David S. Miller,
	Herbert Xu, Steffen Klassert, netdev

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" <davem@davemloft.net>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: netdev@vger.kernel.org
Fairly-blamed-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 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;
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] netlink: Make groups check less stupid in netlink_bind()
  2018-09-03 21:40 [PATCH] netlink: Make groups check less stupid in netlink_bind() Dmitry Safonov
@ 2018-09-06  5:11 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-09-06  5:11 UTC (permalink / raw)
  To: dima
  Cc: linux-kernel, 0x7f454c46, torvalds, herbert, steffen.klassert, netdev

From: Dmitry Safonov <dima@arista.com>
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" <davem@davemloft.net>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: Steffen Klassert <steffen.klassert@secunet.com>
> Cc: netdev@vger.kernel.org
> Fairly-blamed-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Dmitry Safonov <dima@arista.com>

Applied to net-next, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-06  5:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 21:40 [PATCH] netlink: Make groups check less stupid in netlink_bind() Dmitry Safonov
2018-09-06  5:11 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.