Skip to contentSkip to conversation

octeontx2-pf: fix an off by one bug in otx2_get_fecparam()

PATCH In review Dan Carpenter 2 participants 2 messages Feb 15, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 octeontx2-pf: fix an off by one bug in otx2_get_fecparam()

The "<= FEC_MAX_INDEX" comparison should be "< FEC_MAX_INDEX".

I did some cleanup in this function to hopefully make the code a bit clearer. There was no blank line after the declaration block. The closing curly brace on the fec[] declaration normally goes on a line by itself. And I removed the FEC_MAX_INDEX define and used ARRAY_SIZE(fec) instead.

Fixes d0cf9503e908 ("octeontx2-pf: ethtool fec mode support")
---
 .../net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c    | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +5 -4
index 237e5d3321d4..0eaf11107cb7 100644
@@ -955,16 +955,17 @@ static int otx2_get_fecparam(struct net_device *netdev,
 		ETHTOOL_FEC_OFF,
 		ETHTOOL_FEC_BASER,
 		ETHTOOL_FEC_RS,
-		ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS};
-#define FEC_MAX_INDEX 4
-	if (pfvf->linfo.fec < FEC_MAX_INDEX)
+		ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS,
+	};
+
+	if (pfvf->linfo.fec < ARRAY_SIZE(fec))
 		fecparam->active_fec = fec[pfvf->linfo.fec];
 
 	rsp = otx2_get_fwdata(pfvf);
 	if (IS_ERR(rsp))
 		return PTR_ERR(rsp);
 
-	if (rsp->fwdata.supported_fec <= FEC_MAX_INDEX) {
+	if (rsp->fwdata.supported_fec < ARRAY_SIZE(fec)) {
 		if (!rsp->fwdata.supported_fec)
 			fecparam->fec = ETHTOOL_FEC_NONE;
 		else
Signature · 1 line
2.30.0
maintainer
#1 lore raw

From: Dan Carpenter <[email protected]>
Date: Mon, 15 Feb 2021 18:56:46 +0300

Quoted 10 lines

The "<= FEC_MAX_INDEX" comparison should be "< FEC_MAX_INDEX".

I did some cleanup in this function to hopefully make the code a bit clearer. There was no blank line after the declaration block. The closing curly brace on the fec[] declaration normally goes on a line by itself. And I removed the FEC_MAX_INDEX define and used ARRAY_SIZE(fec) instead.

Fixes d0cf9503e908 ("octeontx2-pf: ethtool fec mode support")

This doesn't apply to net-next.