From: Andy Moreton <amore...@solarflare.com>

Previously the code relied on the callers of efx_mcdi_mac_stats
to provide a DMA buffer or NULL depnding on the action. Fix
this so that the DMA buffer is only passed in the request when
needed, and that an error is reported for a missing DMA buffer.

Signed-off-by: Andy Moreton <amore...@solarflare.com>
Signed-off-by: Andrew Rybchenko <arybche...@solarflare.com>
---
 drivers/net/sfc/base/efx_mcdi.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/sfc/base/efx_mcdi.c b/drivers/net/sfc/base/efx_mcdi.c
index 3352b08..a593b3f 100644
--- a/drivers/net/sfc/base/efx_mcdi.c
+++ b/drivers/net/sfc/base/efx_mcdi.c
@@ -1814,9 +1814,15 @@ efx_mcdi_mac_stats(
            MAC_STATS_IN_PERIODIC_NOEVENT, !events,
            MAC_STATS_IN_PERIOD_MS, (enable | events) ? period_ms : 0);
 
-       if (esmp != NULL) {
+       if (enable || events || upload) {
                uint32_t bytes = MC_CMD_MAC_NSTATS * sizeof (uint64_t);
 
+               /* Periodic stats or stats upload require a DMA buffer */
+               if (esmp == NULL) {
+                       rc = EINVAL;
+                       goto fail1;
+               }
+
                EFX_STATIC_ASSERT(MC_CMD_MAC_NSTATS * sizeof (uint64_t) <=
                    EFX_MAC_STATS_SIZE);
 
@@ -1827,8 +1833,6 @@ efx_mcdi_mac_stats(
                MCDI_IN_SET_DWORD(req, MAC_STATS_IN_DMA_ADDR_HI,
                            EFSYS_MEM_ADDR(esmp) >> 32);
                MCDI_IN_SET_DWORD(req, MAC_STATS_IN_DMA_LEN, bytes);
-       } else {
-               EFSYS_ASSERT(!upload && !enable && !events);
        }
 
        /*
@@ -1846,12 +1850,14 @@ efx_mcdi_mac_stats(
                if ((req.emr_rc != ENOENT) ||
                    (enp->en_rx_qcount + enp->en_tx_qcount != 0)) {
                        rc = req.emr_rc;
-                       goto fail1;
+                       goto fail2;
                }
        }
 
        return (0);
 
+fail2:
+       EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
 
-- 
2.7.4

Reply via email to