linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] octeontx2-pf: fix an off by one bug in otx2_get_fecparam()
@ 2021-02-15 15:56 Dan Carpenter
  2021-02-15 20:57 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-02-15 15:56 UTC (permalink / raw)
  To: Sunil Goutham, Christina Jacob
  Cc: Geetha sowjanya, Subbaraya Sundeep, hariprasad, David S. Miller,
	Jakub Kicinski, Jesse Brandeburg, netdev, linux-kernel,
	kernel-janitors

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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 .../net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c    | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
index 237e5d3321d4..0eaf11107cb7 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
@@ -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
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] octeontx2-pf: fix an off by one bug in otx2_get_fecparam()
  2021-02-15 15:56 [PATCH net-next] octeontx2-pf: fix an off by one bug in otx2_get_fecparam() Dan Carpenter
@ 2021-02-15 20:57 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2021-02-15 20:57 UTC (permalink / raw)
  To: dan.carpenter
  Cc: sgoutham, cjacob, gakula, sbhatta, hkelam, kuba,
	jesse.brandeburg, netdev, linux-kernel, kernel-janitors

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Mon, 15 Feb 2021 18:56:46 +0300

> 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

This doesn't apply to net-next.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-15 20:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 15:56 [PATCH net-next] octeontx2-pf: fix an off by one bug in otx2_get_fecparam() Dan Carpenter
2021-02-15 20:57 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).