netlink: Don't use int as bool in netlink_update_socket_mc()
Subsystems (2)
PATCH RESEND 1/1 netlink: Don't use int as bool in netlink_update_socket_mc()
The bit operations take boolean parameter and return also boolean (in test_bit()-like cases). Don't threat booleans as integers when it's not needed.
--- net/netlink/af_netlink.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/netlink/af_netlink.c +4 -3
@@ -1623,9 +1623,10 @@ EXPORT_SYMBOL(netlink_set_err);/* must be called with netlink table grabbed */ static void netlink_update_socket_mc (struct netlink_sock *nlk,unsigned int group, -int is_new) +bool new) { -int old, new = !!is_new, subscriptions; +int subscriptions; +bool old; old =test_bit (group -1 , nlk->groups); subscriptions = nlk->subscriptions - old + new;
@@ -2152,7 +2153,7 @@ void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group)struct netlink_table *tbl = &nl_table[ksk->sk_protocol];sk_for_each_bound (sk, &tbl->mc_list) -netlink_update_socket_mc (nlk_sk (sk), group,0 ); +netlink_update_socket_mc (nlk_sk (sk), group, false); } struct nlmsghdr *
Signature · 1 line
2.40.0.1.gaa8946217a0b
Quoted 16 lines · Andy Shevchenko
The bit operations take boolean parameter and return also boolean (in test_bit()-like cases). Don't threat booleans as integers when it's not needed.
Signed-off-by Andy Shevchenko <[email protected]>--- net/netlink/af_netlink.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)net/netlink/af_netlink.c +0
-0@@ -1623,9 +1623,10 @@ EXPORT_SYMBOL(netlink_set_err);/* must be called with netlink table grabbed */ static void netlink_update_socket_mc(struct netlink_sock *nlk,
net/netlink/af_netlink.c EXPORT_SYMBOL(netlink_set_err); · line 1632
Quoted 10 lines
net/netlink/af_netlink.c +3
-2unsigned int group, - int is_new) + bool new) { - int old, new = !!is_new, subscriptions; + int subscriptions; +bool old; old =test_bit (group -1 , nlk->groups); subscriptions = nlk->subscriptions - old + new;
So what is the outcome of "int - bool + bool" in the line above?
Quoted 13 lines
net/netlink/af_netlink.c +1
-1@@ -2152,7 +2153,7 @@ void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group)struct netlink_table *tbl = &nl_table[ksk->sk_protocol];sk_for_each_bound (sk, &tbl->mc_list) -netlink_update_socket_mc (nlk_sk (sk), group,0 ); +netlink_update_socket_mc (nlk_sk (sk), group, false); } struct nlmsghdr *Signature · 1 line
2.40.0.1.gaa8946217a0b
Paolo Abeni
maintainerQuoted 25 lines · Leon Romanovsky
Quoted 24 lines · Andy Shevchenko
The bit operations take boolean parameter and return also boolean (in test_bit()-like cases). Don't threat booleans as integers when it's not needed.
Signed-off-by Andy Shevchenko <[email protected]>--- net/netlink/af_netlink.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)net/netlink/af_netlink.c +3
-2@@ -1623,9 +1623,10 @@ EXPORT_SYMBOL(netlink_set_err);/* must be called with netlink table grabbed */ static void netlink_update_socket_mc (struct netlink_sock *nlk,unsigned int group, -int is_new) +bool new) { -int old, new = !!is_new, subscriptions; +int subscriptions; +bool old;
Quoted 4 lines
net/netlink/af_netlink.c EXPORT_SYMBOL(netlink_set_err); · line 1632
Quoted 2 lines
net/netlink/af_netlink.c +0
-0old =test_bit (group -1 , nlk->groups); subscriptions = nlk->subscriptions - old + new;So what is the outcome of "int - bool + bool" in the line above?
FTR, I agree with Leon, the old code is more readable to me/I don't see a practical gain with this change.
Cheers,
Paolo
Quoted 26 lines · Paolo Abeni
Quoted 25 lines · Leon Romanovsky
Quoted 24 lines · Andy Shevchenko
The bit operations take boolean parameter and return also boolean (in test_bit()-like cases). Don't threat booleans as integers when it's not needed.
Signed-off-by Andy Shevchenko <[email protected]>--- net/netlink/af_netlink.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)net/netlink/af_netlink.c +3
-2@@ -1623,9 +1623,10 @@ EXPORT_SYMBOL(netlink_set_err);/* must be called with netlink table grabbed */ static void netlink_update_socket_mc (struct netlink_sock *nlk,unsigned int group, -int is_new) +bool new) { -int old, new = !!is_new, subscriptions; +int subscriptions; +bool old;
Quoted 4 lines
Quoted 4 lines
net/netlink/af_netlink.c EXPORT_SYMBOL(netlink_set_err); · line 1632
Quoted 2 lines
net/netlink/af_netlink.c +0
-0old =test_bit (group -1 , nlk->groups); subscriptions = nlk->subscriptions - old + new;So what is the outcome of "int - bool + bool" in the line above?
The same as with int - int [0 .. 1] + int [0 .. 1].
Note, the code _already_ uses boolean as integers.
Quoted 2 lines
FTR, I agree with Leon, the old code is more readable to me/I don't see a practical gain with this change.
This change does not change the status quo. The code uses booleans as integers already (in the callers).
As I mentioned earlier, the purity of the code (converting booleans to integers beforehand) adds unneeded churn and with this change code becomes cleaner at least for the (existing) callers.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 27 lines · Andy Shevchenko
Quoted 26 lines · Paolo Abeni
Quoted 25 lines · Leon Romanovsky
Quoted 24 lines · Andy Shevchenko
The bit operations take boolean parameter and return also boolean (in test_bit()-like cases). Don't threat booleans as integers when it's not needed.
Signed-off-by Andy Shevchenko <[email protected]>--- net/netlink/af_netlink.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)net/netlink/af_netlink.c +3
-2@@ -1623,9 +1623,10 @@ EXPORT_SYMBOL(netlink_set_err);/* must be called with netlink table grabbed */ static void netlink_update_socket_mc (struct netlink_sock *nlk,unsigned int group, -int is_new) +bool new) { -int old, new = !!is_new, subscriptions; +int subscriptions; +bool old;
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
net/netlink/af_netlink.c EXPORT_SYMBOL(netlink_set_err); · line 1632
Quoted 2 lines
net/netlink/af_netlink.c +0
-0old =test_bit (group -1 , nlk->groups); subscriptions = nlk->subscriptions - old + new;So what is the outcome of "int - bool + bool" in the line above?
The same as with int - int [0 .. 1] + int [0 .. 1].
No, it is not. bool is defined as _Bool C99 type, so strictly speaking you are mixing types int - _Bool + _Bool.
Thanks
Quoted 18 lines
Note, the code _already_ uses boolean as integers.
Quoted 2 lines
FTR, I agree with Leon, the old code is more readable to me/I don't see a practical gain with this change.
This change does not change the status quo. The code uses booleans as integers already (in the callers).
As I mentioned earlier, the purity of the code (converting booleans to integers beforehand) adds unneeded churn and with this change code becomes cleaner at least for the (existing) callers.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · Leon Romanovsky
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Paolo Abeni
Quoted 1 line · Leon Romanovsky
On Mon, Jul 10, 2023 at 01:06:24PM +0300, Andy Shevchenko wrote:
...
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So what is the outcome of "int - bool + bool" in the line above?
The same as with int - int [0 .. 1] + int [0 .. 1].
No, it is not. bool is defined as
_BoolC99 type, so strictly speaking you are mixing types int -_Bool+_Bool.
1. The original code already does that. You still haven't reacted on that.
2. Is what you are telling a problem?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Leon Romanovsky
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Paolo Abeni
Quoted 1 line · Leon Romanovsky
On Mon, Jul 10, 2023 at 01:06:24PM +0300, Andy Shevchenko wrote:
...
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So what is the outcome of "int - bool + bool" in the line above?
The same as with int - int [0 .. 1] + int [0 .. 1].
No, it is not. bool is defined as
_BoolC99 type, so strictly speaking you are mixing types int -_Bool+_Bool.1. The original code already does that. You still haven't reacted on that.
The original code was int - int + int.
Quoted 1 line
2. Is what you are telling a problema?
No, I'm saying that you took perfectly correct code which had all types aligned and changed it to have mixed type arithmetic.
Thanks
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
Quoted 6 lines · Leon Romanovsky
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Leon Romanovsky
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Paolo Abeni
Quoted 1 line · Leon Romanovsky
On Mon, Jul 10, 2023 at 01:06:24PM +0300, Andy Shevchenko wrote:
...
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So what is the outcome of "int - bool + bool" in the line above?
The same as with int - int [0 .. 1] + int [0 .. 1].
No, it is not. bool is defined as
_BoolC99 type, so strictly speaking you are mixing types int -_Bool+_Bool.1. The original code already does that. You still haven't reacted on that.
The original code was int - int + int.
No. You missed the callers part. They are using boolean.
Quoted 4 lines
Quoted 1 line
2. Is what you are telling a problema?
No, I'm saying that you took perfectly correct code which had all types aligned and changed it to have mixed type arithmetic.
And after this change it's perfectly correct code with less letters and hidden promotions (as a parameter to the function) and hence requires less cognitive energy to parse.
So, the bottom line is the commit message you don't like, is it so?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 14 lines · Andy Shevchenko
Quoted 6 lines · Leon Romanovsky
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Leon Romanovsky
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Paolo Abeni
Quoted 1 line · Leon Romanovsky
On Mon, Jul 10, 2023 at 01:06:24PM +0300, Andy Shevchenko wrote:
...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So what is the outcome of "int - bool + bool" in the line above?
The same as with int - int [0 .. 1] + int [0 .. 1].
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
No, it is not. bool is defined as
_BoolC99 type, so strictly speaking you are mixing types int -_Bool+_Bool.1. The original code already does that. You still haven't reacted on that.
The original code was int - int + int.
No. You missed the callers part. They are using boolean.
I didn't miss and pointed you to the exact line which was implicitly changed with your patch.
Quoted 11 lines
Quoted 5 lines
Quoted 2 lines
2. Is what you are telling a problema?
No, I'm saying that you took perfectly correct code which had all types aligned and changed it to have mixed type arithmetic.
And after this change it's perfectly correct code with less letters and hidden promotions (as a parameter to the function) and hence requires less cognitive energy to parse.
So, the bottom line is the commit message you don't like, is it so?
Please reread my and Paolo replies.
Thanks
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
Quoted 8 lines · Leon Romanovsky
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Leon Romanovsky
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Leon Romanovsky
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Paolo Abeni
Quoted 1 line · Leon Romanovsky
On Mon, Jul 10, 2023 at 01:06:24PM +0300, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So what is the outcome of "int - bool + bool" in the line above?
The same as with int - int [0 .. 1] + int [0 .. 1].
No, it is not. bool is defined as
_BoolC99 type, so strictly speaking you are mixing types int -_Bool+_Bool.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
1. The original code already does that. You still haven't reacted on that.
The original code was int - int + int.
No. You missed the callers part. They are using boolean.
I didn't miss and pointed you to the exact line which was implicitly changed with your patch.
Yes, and this line doesn't change the status quo. We have boolean in the callers that implicitly went to the callee as int.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
2. Is what you are telling a problema?
No, I'm saying that you took perfectly correct code which had all types aligned and changed it to have mixed type arithmetic.
Quoted 7 lines
Quoted 5 lines
And after this change it's perfectly correct code with less letters and hidden promotions (as a parameter to the function) and hence requires less cognitive energy to parse.
So, the bottom line is the commit message you don't like, is it so?
Please reread my and Paolo replies.
I have read them. My point is that you should also look at the callers to see the big picture.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jakub Kicinski
maintainerQuoted 3 lines · On Mon, 10 Jul 2023 13:06:24 +0300 Andy Shevchenko wrote:
The bit operations take boolean parameter and return also boolean (in test_bit()-like cases). Don't threat booleans as integers when it's not needed.
I don't have a strong opinion on the merit.
But I feel like the discussion is a waste of everyone's time, so to discourage such ambivalent patches I'm going to drop this.
Signature · 1 line
pw-bot: reject