Skip to contentSkip to conversation

net/core: Make use of assign_bit() API

PATCH Superseded Andy Shevchenko 2 participants 3 messages Jun 29, 2023

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 2/2 netlink: Make use of __assign_bit() API

In reply to Andy Shevchenko

We have for some time the __assign_bit() API to replace open coded

	if (foo)
		__set_bit(n, bar);
	else
		__clear_bit(n, bar);

Use this API in the code. No functional change intended.

---
 net/netlink/af_netlink.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
net/netlink/af_netlink.c +1 -4
index 383631873748..9c9df143a2ec 100644
@@ -1629,10 +1629,7 @@ static void netlink_update_socket_mc(struct netlink_sock *nlk,
 
 	old = test_bit(group - 1, nlk->groups);
 	subscriptions = nlk->subscriptions - old + new;
-	if (new)
-		__set_bit(group - 1, nlk->groups);
-	else
-		__clear_bit(group - 1, nlk->groups);
+	__assign_bit(group - 1, nlk->groups, new);
 	netlink_update_subscriptions(&nlk->sk, subscriptions);
 	netlink_update_listeners(&nlk->sk);
 }
Signature · 1 line
2.40.0.1.gaa8946217a0b
#0 lore raw

PATCH 1/2 net/core: Make use of assign_bit() API

We have for some time the assign_bit() API to replace open coded

	if (foo)
		set_bit(n, bar);
	else
		clear_bit(n, bar);

Use this API in the code. No functional change intended.

---
 net/core/dev.c  |  8 ++------
 net/core/sock.c | 15 +++------------
 2 files changed, 5 insertions(+), 18 deletions(-)
net/core/dev.c +2 -6
index 69a3e544676c..d6e1b786c5c5 100644
@@ -6316,12 +6316,8 @@ int dev_set_threaded(struct net_device *dev, bool threaded)
 	 * softirq mode will happen in the next round of napi_schedule().
 	 * This should not cause hiccups/stalls to the live traffic.
 	 */
-	list_for_each_entry(napi, &dev->napi_list, dev_list) {
-		if (threaded)
-			set_bit(NAPI_STATE_THREADED, &napi->state);
-		else
-			clear_bit(NAPI_STATE_THREADED, &napi->state);
-	}
+	list_for_each_entry(napi, &dev->napi_list, dev_list)
+		assign_bit(NAPI_STATE_THREADED, &napi->state, threaded);
 
 	return err;
 }
net/core/sock.c +3 -12
index 9370fd50aa2c..ab1e8d1bd5a1 100644
@@ -1244,17 +1244,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 		break;
 
 	case SO_PASSCRED:
-		if (valbool)
-			set_bit(SOCK_PASSCRED, &sock->flags);
-		else
-			clear_bit(SOCK_PASSCRED, &sock->flags);
+		assign_bit(SOCK_PASSCRED, &sock->flags, valbool);
 		break;
 
 	case SO_PASSPIDFD:
-		if (valbool)
-			set_bit(SOCK_PASSPIDFD, &sock->flags);
-		else
-			clear_bit(SOCK_PASSPIDFD, &sock->flags);
+		assign_bit(SOCK_PASSPIDFD, &sock->flags, valbool);
 		break;
 
 	case SO_TIMESTAMP_OLD:
@@ -1358,10 +1352,7 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 		break;
 
 	case SO_PASSSEC:
-		if (valbool)
-			set_bit(SOCK_PASSSEC, &sock->flags);
-		else
-			clear_bit(SOCK_PASSSEC, &sock->flags);
+		assign_bit(SOCK_PASSSEC, &sock->flags, valbool);
 		break;
 	case SO_MARK:
 		if (!sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_RAW) &&
Signature · 1 line
2.40.0.1.gaa8946217a0b
#2 lore raw
Quoted 10 lines · Andy Shevchenko

We have for some time the assign_bit() API to replace open coded

	if (foo)
		set_bit(n, bar);
	else
		clear_bit(n, bar);

Use this API in the code. No functional change intended.

Hi Andy,

I'm assuming this is targeted at 'net-next', as opposed to 'net', which is for fixes. In any case, the target tree should be included in the subject.

Subject: [PATCH net-next v2] ...

If it is for net-next, then please repost when net-next reopens after July 10th.

Signature · 1 line
pw-bot: deferred