]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
octeontx2-pf: Remove unnecessary bounds check
authorSimon Horman <horms@kernel.org>
Mon, 19 Jan 2026 16:39:37 +0000 (16:39 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 21 Jan 2026 02:28:35 +0000 (18:28 -0800)
active_fec is a 2-bit unsigned field, and thus can only have the values
0-3. So checking that it is less than 4 is unnecessary.

Simplify the code by dropping this check.

As it no longer fits well where it is, move FEC_MAX_INDEX to towards the
top of the file. And add the prefix OXT2.  I believe this is more
idiomatic.

Flagged by Smatch as:
  ...//otx2_ethtool.c:1024 otx2_get_fecparam() warn: always true condition '(pfvf->linfo.fec < 4) => (0-3 < 4)'

No functional change intended.
Compile tested only.

Signed-off-by: Simon Horman <horms@kernel.org>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>
Link: https://patch.msgid.link/20260119-oob-v1-1-a4147e75e770@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c

index 8918be3ce45e9ae2e1f2fbc6396df0ab6c85bc22..a0340f3422bf90af524f682fc1fbe211d64c129c 100644 (file)
@@ -66,6 +66,8 @@ static const struct otx2_stat otx2_queue_stats[] = {
        { "frames", 1 },
 };
 
+#define OTX2_FEC_MAX_INDEX 4
+
 static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats);
 static const unsigned int otx2_n_drv_stats = ARRAY_SIZE(otx2_drv_stats);
 static const unsigned int otx2_n_queue_stats = ARRAY_SIZE(otx2_queue_stats);
@@ -1031,15 +1033,14 @@ static int otx2_get_fecparam(struct net_device *netdev,
                ETHTOOL_FEC_BASER,
                ETHTOOL_FEC_RS,
                ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS};
-#define FEC_MAX_INDEX 4
-       if (pfvf->linfo.fec < FEC_MAX_INDEX)
-               fecparam->active_fec = fec[pfvf->linfo.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 < OTX2_FEC_MAX_INDEX) {
                if (!rsp->fwdata.supported_fec)
                        fecparam->fec = ETHTOOL_FEC_NONE;
                else