Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Mar 2023 17:51:54 GMT
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 5a8abd0a298e - main - lacp: Use C99 bool for boolean return value
Message-ID:  <202303311751.32VHpsGN073972@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by zlei:

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

commit 5a8abd0a298e6e7a8bf938a7eb171b647b1860cd
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-03-31 17:48:36 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-03-31 17:48:36 +0000

    lacp: Use C99 bool for boolean return value
    
    This improves readability.
    
    No functional change intended.
    
    MFC after:      1 week
---
 sys/net/ieee8023ad_lacp.c | 38 +++++++++++++++++---------------------
 sys/net/ieee8023ad_lacp.h | 15 ++++++---------
 sys/net/if_lagg.c         |  2 +-
 3 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/sys/net/ieee8023ad_lacp.c b/sys/net/ieee8023ad_lacp.c
index 78345aae68e5..52b4b478bbc7 100644
--- a/sys/net/ieee8023ad_lacp.c
+++ b/sys/net/ieee8023ad_lacp.c
@@ -117,9 +117,9 @@ static void	lacp_fill_aggregator_id(struct lacp_aggregator *,
 		    const struct lacp_port *);
 static void	lacp_fill_aggregator_id_peer(struct lacp_peerinfo *,
 		    const struct lacp_peerinfo *);
-static int	lacp_aggregator_is_compatible(const struct lacp_aggregator *,
+static bool	lacp_aggregator_is_compatible(const struct lacp_aggregator *,
 		    const struct lacp_port *);
-static int	lacp_peerinfo_is_compatible(const struct lacp_peerinfo *,
+static bool	lacp_peerinfo_is_compatible(const struct lacp_peerinfo *,
 		    const struct lacp_peerinfo *);
 
 static struct lacp_aggregator *lacp_aggregator_get(struct lacp_softc *,
@@ -1365,44 +1365,40 @@ lacp_fill_aggregator_id_peer(struct lacp_peerinfo *lpi_aggr,
  * lacp_aggregator_is_compatible: check if a port can join to an aggregator.
  */
 
-static int
+static bool
 lacp_aggregator_is_compatible(const struct lacp_aggregator *la,
     const struct lacp_port *lp)
 {
 	if (!(lp->lp_state & LACP_STATE_AGGREGATION) ||
 	    !(lp->lp_partner.lip_state & LACP_STATE_AGGREGATION)) {
-		return (0);
+		return (false);
 	}
 
-	if (!(la->la_actor.lip_state & LACP_STATE_AGGREGATION)) {
-		return (0);
-	}
+	if (!(la->la_actor.lip_state & LACP_STATE_AGGREGATION))
+		return (false);
 
-	if (!lacp_peerinfo_is_compatible(&la->la_partner, &lp->lp_partner)) {
-		return (0);
-	}
+	if (!lacp_peerinfo_is_compatible(&la->la_partner, &lp->lp_partner))
+		return (false);
 
-	if (!lacp_peerinfo_is_compatible(&la->la_actor, &lp->lp_actor)) {
-		return (0);
-	}
+	if (!lacp_peerinfo_is_compatible(&la->la_actor, &lp->lp_actor))
+		return (false);
 
-	return (1);
+	return (true);
 }
 
-static int
+static bool
 lacp_peerinfo_is_compatible(const struct lacp_peerinfo *a,
     const struct lacp_peerinfo *b)
 {
 	if (memcmp(&a->lip_systemid, &b->lip_systemid,
-	    sizeof(a->lip_systemid))) {
-		return (0);
+	    sizeof(a->lip_systemid)) != 0) {
+		return (false);
 	}
 
-	if (memcmp(&a->lip_key, &b->lip_key, sizeof(a->lip_key))) {
-		return (0);
-	}
+	if (memcmp(&a->lip_key, &b->lip_key, sizeof(a->lip_key)) != 0)
+		return (false);
 
-	return (1);
+	return (true);
 }
 
 static void
diff --git a/sys/net/ieee8023ad_lacp.h b/sys/net/ieee8023ad_lacp.h
index 0610ed855d50..629bdc25cfc5 100644
--- a/sys/net/ieee8023ad_lacp.h
+++ b/sys/net/ieee8023ad_lacp.h
@@ -307,7 +307,7 @@ void		lacp_linkstate(struct lagg_port *);
 void		lacp_req(struct lagg_softc *, void *);
 void		lacp_portreq(struct lagg_port *, void *);
 
-static __inline int
+static __inline bool
 lacp_isactive(struct lagg_port *lgp)
 {
 	struct lacp_port *lp = LACP_PORT(lgp);
@@ -315,26 +315,23 @@ lacp_isactive(struct lagg_port *lgp)
 	struct lacp_aggregator *la = lp->lp_aggregator;
 
 	/* This port is joined to the active aggregator */
-	if (la != NULL && la == lsc->lsc_active_aggregator)
-		return (1);
-
-	return (0);
+	return (la != NULL && la == lsc->lsc_active_aggregator);
 }
 
-static __inline int
+static __inline bool
 lacp_iscollecting(struct lagg_port *lgp)
 {
 	struct lacp_port *lp = LACP_PORT(lgp);
 
-	return ((lp->lp_state & LACP_STATE_COLLECTING) != 0);
+	return (lp->lp_state & LACP_STATE_COLLECTING);
 }
 
-static __inline int
+static __inline bool
 lacp_isdistributing(struct lagg_port *lgp)
 {
 	struct lacp_port *lp = LACP_PORT(lgp);
 
-	return ((lp->lp_state & LACP_STATE_DISTRIBUTING) != 0);
+	return (lp->lp_state & LACP_STATE_DISTRIBUTING);
 }
 
 /* following constants don't include terminating NUL */
diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c
index 063782b49ad7..cf78b55f4c34 100644
--- a/sys/net/if_lagg.c
+++ b/sys/net/if_lagg.c
@@ -2685,7 +2685,7 @@ lagg_lacp_input(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
 	 * If the port is not collecting or not in the active aggregator then
 	 * free and return.
 	 */
-	if (lacp_iscollecting(lp) == 0 || lacp_isactive(lp) == 0) {
+	if (!lacp_iscollecting(lp) || !lacp_isactive(lp)) {
 		m_freem(m);
 		return (NULL);
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202303311751.32VHpsGN073972>