]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
net: xilinx: axienet: Report an error for bad coalesce settings
authorSean Anderson <sean.anderson@linux.dev>
Thu, 16 Jan 2025 23:29:50 +0000 (18:29 -0500)
committerJakub Kicinski <kuba@kernel.org>
Sun, 19 Jan 2025 01:18:53 +0000 (17:18 -0800)
Instead of silently ignoring invalid/unsupported settings, report an
error. Additionally, relax the check for non-zero usecs to apply only
when it will be used (i.e. when frames != 1).

Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Reviewed by: Shannon Nelson <shannon.nelson@amd.com>
Link: https://patch.msgid.link/20250116232954.2696930-3-sean.anderson@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/xilinx/xilinx_axienet_main.c

index 0532dc94ee937f203e4a963fdc46bd8b2b192a62..9e7fa012e4fad7fb19f980b2e3f663bd71cc5981 100644 (file)
@@ -2059,14 +2059,25 @@ axienet_ethtools_set_coalesce(struct net_device *ndev,
                return -EINVAL;
        }
 
-       if (ecoalesce->rx_max_coalesced_frames)
-               lp->coalesce_count_rx = ecoalesce->rx_max_coalesced_frames;
-       if (ecoalesce->rx_coalesce_usecs)
-               lp->coalesce_usec_rx = ecoalesce->rx_coalesce_usecs;
-       if (ecoalesce->tx_max_coalesced_frames)
-               lp->coalesce_count_tx = ecoalesce->tx_max_coalesced_frames;
-       if (ecoalesce->tx_coalesce_usecs)
-               lp->coalesce_usec_tx = ecoalesce->tx_coalesce_usecs;
+       if (!ecoalesce->rx_max_coalesced_frames ||
+           !ecoalesce->tx_max_coalesced_frames) {
+               NL_SET_ERR_MSG(extack, "frames must be non-zero");
+               return -EINVAL;
+       }
+
+       if ((ecoalesce->rx_max_coalesced_frames > 1 &&
+            !ecoalesce->rx_coalesce_usecs) ||
+           (ecoalesce->tx_max_coalesced_frames > 1 &&
+            !ecoalesce->tx_coalesce_usecs)) {
+               NL_SET_ERR_MSG(extack,
+                              "usecs must be non-zero when frames is greater than one");
+               return -EINVAL;
+       }
+
+       lp->coalesce_count_rx = ecoalesce->rx_max_coalesced_frames;
+       lp->coalesce_usec_rx = ecoalesce->rx_coalesce_usecs;
+       lp->coalesce_count_tx = ecoalesce->tx_max_coalesced_frames;
+       lp->coalesce_usec_tx = ecoalesce->tx_coalesce_usecs;
 
        return 0;
 }