git: d34678395f3f - main - ifnet/API: Change if_set*bit accessors to clear first

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Mon, 09 Jan 2023 20:55:03 UTC
The branch main has been updated by jhibbits:

URL: https://cgit.FreeBSD.org/src/commit/?id=d34678395f3f24df6cee899fcfe7f76b99cae426

commit d34678395f3f24df6cee899fcfe7f76b99cae426
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2023-01-09 19:24:08 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2023-01-09 21:00:22 +0000

    ifnet/API: Change if_set*bit accessors to clear first
    
    Summary:
    A common pattern has been to:
    
            if (foo)
                    caps = IFCAP_FOO;
            ifp->if_capenable &= ~IFCAP_FOO;
            ifp->if_capenable |= caps;
    
    which in the new order of things would be:
    
            if (foo)
                    caps = IF_FOO;
            if_setcapenablebits(ifp, 0, IFCAP_FOO);
            if_setcapenablebits(ifp, caps, 0);
    
    This change streamlines this into:
    
            if (foo)
                    caps = IF_FOO;
            if_setcapenablebits(ifp, caps, IFCAP_FOO);
    
    Reviewed by:    melifaro
    Sponsored by:   Juniper Networks, Inc.
    Differential Revision: https://reviews.freebsd.org/D37993
---
 sys/net/if.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index 3b2256bd94ff..c7b7d1f6d9d4 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -4211,8 +4211,8 @@ if_setcapabilities(if_t ifp, int capabilities)
 int
 if_setcapabilitiesbit(if_t ifp, int setbit, int clearbit)
 {
-	((struct ifnet *)ifp)->if_capabilities |= setbit;
 	((struct ifnet *)ifp)->if_capabilities &= ~clearbit;
+	((struct ifnet *)ifp)->if_capabilities |= setbit;
 
 	return (0);
 }
@@ -4233,10 +4233,10 @@ if_setcapenable(if_t ifp, int capabilities)
 int 
 if_setcapenablebit(if_t ifp, int setcap, int clearcap)
 {
-	if(setcap) 
-		((struct ifnet *)ifp)->if_capenable |= setcap;
 	if(clearcap)
 		((struct ifnet *)ifp)->if_capenable &= ~clearcap;
+	if(setcap) 
+		((struct ifnet *)ifp)->if_capenable |= setcap;
 
 	return (0);
 }
@@ -4339,8 +4339,8 @@ if_setdev(if_t ifp, void *dev)
 int
 if_setdrvflagbits(if_t ifp, int set_flags, int clear_flags)
 {
-	((struct ifnet *)ifp)->if_drv_flags |= set_flags;
 	((struct ifnet *)ifp)->if_drv_flags &= ~clear_flags;
+	((struct ifnet *)ifp)->if_drv_flags |= set_flags;
 
 	return (0);
 }
@@ -4369,8 +4369,8 @@ if_setflags(if_t ifp, int flags)
 int
 if_setflagbits(if_t ifp, int set, int clear)
 {
-	((struct ifnet *)ifp)->if_flags |= set;
 	((struct ifnet *)ifp)->if_flags &= ~clear;
+	((struct ifnet *)ifp)->if_flags |= set;
 
 	return (0);
 }
@@ -4391,8 +4391,8 @@ if_clearhwassist(if_t ifp)
 int
 if_sethwassistbits(if_t ifp, int toset, int toclear)
 {
-	((struct ifnet *)ifp)->if_hwassist |= toset;
 	((struct ifnet *)ifp)->if_hwassist &= ~toclear;
+	((struct ifnet *)ifp)->if_hwassist |= toset;
 
 	return (0);
 }