[PATCH v2 04/14] common/sfc_efx/base: reduce stack in netport stat describe

Ivan Malov <[email protected]>
Newsgroups org.dpdk.dev
Message-ID <[email protected]>
From: Andy Moreton <[email protected]>

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

Fixes: f2f77453cb9f ("common/sfc_efx/base: fill in software LUT for MAC statistics")
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_np.c | 37 +++++++++++++++++++---------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/drivers/common/sfc_efx/base/efx_np.c b/drivers/common/sfc_efx/base/efx_np.c
index 45f3cd07ed..5044eabdd3 100644
--- a/drivers/common/sfc_efx/base/efx_np.c
+++ b/drivers/common/sfc_efx/base/efx_np.c
@@ -778,22 +778,30 @@ efx_np_stats_describe(
 	__out_opt			uint32_t *nprocessedp,
 	__out_opt			uint32_t *nstats_maxp)
 {
-	EFX_MCDI_DECLARE_BUF(payload,
-	    MC_CMD_MAC_STATISTICS_DESCRIPTOR_IN_LEN,
-	    MC_CMD_MAC_STATISTICS_DESCRIPTOR_OUT_LENMAX_MCDI2);
+	uint8_t *payload = NULL;
 	uint32_t nprocessed;
 	efx_mcdi_req_t req;
 	uint8_t *entries;
 	uint32_t stride;
 	unsigned int i;
 	size_t out_sz;
+	size_t size;
 	efx_rc_t rc;
 
-	req.emr_out_length = MC_CMD_MAC_STATISTICS_DESCRIPTOR_OUT_LENMAX_MCDI2;
-	req.emr_in_length = MC_CMD_MAC_STATISTICS_DESCRIPTOR_IN_LEN;
+	size = MAX(MC_CMD_MAC_STATISTICS_DESCRIPTOR_IN_LEN,
+	    MC_CMD_MAC_STATISTICS_DESCRIPTOR_OUT_LENMAX_MCDI2);
+
+	EFSYS_KMEM_ALLOC(enp->en_esip, size, payload);
+	if (payload == NULL) {
+		rc = ENOMEM;
+		goto fail1;
+	}
+
 	req.emr_cmd = MC_CMD_MAC_STATISTICS_DESCRIPTOR;
-	req.emr_out_buf = payload;
 	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_MAC_STATISTICS_DESCRIPTOR_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_MAC_STATISTICS_DESCRIPTOR_OUT_LENMAX_MCDI2;
 
 	MCDI_IN_SET_DWORD(req, MAC_STATISTICS_DESCRIPTOR_IN_PORT_HANDLE, nph);
 	MCDI_IN_SET_DWORD(req, MAC_STATISTICS_DESCRIPTOR_IN_OFFSET, req_ofst);
@@ -802,13 +810,13 @@ efx_np_stats_describe(
 
 	if (req.emr_rc != 0) {
 		rc = req.emr_rc;
-		goto fail1;
+		goto fail2;
 	}
 
 	out_sz = req.emr_out_length_used;
 	if (out_sz < MC_CMD_MAC_STATISTICS_DESCRIPTOR_OUT_LENMIN) {
 		rc = EMSGSIZE;
-		goto fail2;
+		goto fail3;
 	}
 
 	if (nstats_maxp != NULL) {
@@ -818,13 +826,13 @@ efx_np_stats_describe(
 	}
 
 	if (lut_nentries == 0 || lut == NULL || nprocessedp == NULL)
-		return (0);
+		goto out;
 
 	stride = MCDI_OUT_DWORD(req, MAC_STATISTICS_DESCRIPTOR_OUT_ENTRY_SIZE);
 	nprocessed = MC_CMD_MAC_STATISTICS_DESCRIPTOR_OUT_ENTRIES_NUM(out_sz);
 	if (nprocessed == 0) {
 		rc = EMSGSIZE;
-		goto fail3;
+		goto fail4;
 	}
 
 	entries = MCDI_OUT2(req, uint8_t,
@@ -834,14 +842,19 @@ efx_np_stats_describe(
 		efx_np_stat_describe(entries + i * stride, lut_nentries, lut);
 
 	*nprocessedp = nprocessed;
+
+out:
+	EFSYS_KMEM_FREE(enp->en_esip, size, payload);
+
 	return (0);
 
+fail4:
+	EFSYS_PROBE(fail4);
 fail3:
 	EFSYS_PROBE(fail3);
-
 fail2:
 	EFSYS_PROBE(fail2);
-
+	EFSYS_KMEM_FREE(enp->en_esip, size, payload);
 fail1:
 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
 	return (rc);
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.