From: Andy Moreton <[email protected]>

Code analysis reports an error for excessive stack consumption
(over 1KB). Use a heap allocated payload buffer instead.

Fixes: 60fb370c7bc9 ("common/sfc_efx/base: support NIC DMA memory regions API")
Cc: [email protected]

Signed-off-by: Andy Moreton <[email protected]>
Reviewed-by: Ivan Malov <[email protected]>
Reviewed-by: Viacheslav Galaktionov <[email protected]>
---
 drivers/common/sfc_efx/base/efx_mcdi.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/common/sfc_efx/base/efx_mcdi.c 
b/drivers/common/sfc_efx/base/efx_mcdi.c
index 7dc58992be..58ad1a1bc1 100644
--- a/drivers/common/sfc_efx/base/efx_mcdi.c
+++ b/drivers/common/sfc_efx/base/efx_mcdi.c
@@ -3550,12 +3550,11 @@ efx_mcdi_set_nic_addr_regions(
        __in            efx_nic_t *enp,
        __in            const efx_nic_dma_region_info_t *endrip)
 {
-       EFX_MCDI_DECLARE_BUF(payload,
-               MC_CMD_SET_DESC_ADDR_REGIONS_IN_LENMAX_MCDI2,
-               MC_CMD_SET_DESC_ADDR_REGIONS_OUT_LEN);
        efx_qword_t *trgt_addr_base;
+       uint8_t *payload = NULL;
        efx_mcdi_req_t req;
        unsigned int i;
+       size_t size;
        efx_rc_t rc;
 
        if (endrip->endri_count >
@@ -3564,6 +3563,15 @@ efx_mcdi_set_nic_addr_regions(
                goto fail1;
        }
 
+       size = MAX(MC_CMD_SET_DESC_ADDR_REGIONS_IN_LEN(endrip->endri_count),
+           MC_CMD_SET_DESC_ADDR_REGIONS_OUT_LEN);
+
+       EFSYS_KMEM_ALLOC(enp->en_esip, size, payload);
+       if (payload == NULL) {
+               rc = ENOMEM;
+               goto fail2;
+       }
+
        req.emr_cmd = MC_CMD_SET_DESC_ADDR_REGIONS;
        req.emr_in_buf = payload;
        req.emr_in_length =
@@ -3598,11 +3606,16 @@ efx_mcdi_set_nic_addr_regions(
 
        if (req.emr_rc != 0) {
                rc = req.emr_rc;
-               goto fail2;
+               goto fail3;
        }
 
+       EFSYS_KMEM_FREE(enp->en_esip, size, payload);
+
        return (0);
 
+fail3:
+       EFSYS_PROBE(fail3);
+       EFSYS_KMEM_FREE(enp->en_esip, size, payload);
 fail2:
        EFSYS_PROBE(fail2);
 fail1:
-- 
2.47.3

Reply via email to