Skip to contentSkip to conversation

net/bnxt: fix free of not allocated object

PATCH In review Stephen Hemminger 1 participant 3 messages May 21, 2025 – Aug 2, 2025 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/bnxt: fix free of not allocated object

This was found as error when compiling with LTO. The function allocates new data with rte_zmalloc and then stores pointer in the pointer-to-pointer passed as argument. In the unwind case, it would call rte_free() with wrong one.

Fixes 80317ff6adfd ("net/bnxt/tf_core: support Thor2")
---
 drivers/net/bnxt/tf_core/v3/tfo.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/bnxt/tf_core/v3/tfo.c +3 -5
index bee813ebf6..c888dd1e4e 100644
@@ -74,9 +74,7 @@ void tfo_open(void **tfo, bool is_pf)
 	rc = cfa_bld_mpc_bind(CFA_P70, &tfco->mpc_info);
 	if (rc) {
 		PMD_DRV_LOG_LINE(ERR, "MPC bind failed");
-		rte_free(tfco);
-		*tfo = NULL;
-		return;
+		goto cleanup;
 	}
 	if (is_pf) {
 		/* Allocate TIM */
@@ -104,8 +102,8 @@ void tfo_open(void **tfo, bool is_pf)
 	return;
 
  cleanup:
-	if (tfco != NULL)
-		rte_free(tfo);
+	rte_free(tfco);
+	*tfo = NULL;
 }
 
 void tfo_close(void **tfo)
Signature · 1 line
2.47.2
#1 lore raw
Quoted 28 lines · On Wed, 21 May 2025 12:37:27 -0700 Stephen Hemminger…

This was found as error when compiling with LTO. The function allocates new data with rte_zmalloc and then stores pointer in the pointer-to-pointer passed as argument. In the unwind case, it would call rte_free() with wrong one.

Fixes 80317ff6adfd ("net/bnxt/tf_core: support Thor2")
---
 drivers/net/bnxt/tf_core/v3/tfo.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/bnxt/tf_core/v3/tfo.c +1 -3
index bee813ebf6..c888dd1e4e 100644
@@ -74,9 +74,7 @@ void tfo_open(void **tfo, bool is_pf)
 	rc = cfa_bld_mpc_bind(CFA_P70, &tfco->mpc_info);
 	if (rc) {
 		PMD_DRV_LOG_LINE(ERR, "MPC bind failed");
-		rte_free(tfco);
-		*tfo = NULL;
-		return;
+		goto cleanup;
 	}
 	if (is_pf) {
 		/* Allocate TIM */

drivers/net/bnxt/tf_core/v3/tfo.c void tfo_open(void **tfo, bool is_pf) · line 109

Quoted 10 lines
drivers/net/bnxt/tf_core/v3/tfo.c +2 -2
@@ -104,8 +102,8 @@ void tfo_open(void **tfo, bool is_pf)
 	return;
 
  cleanup:
-	if (tfco != NULL)
-		rte_free(tfo);
+	rte_free(tfco);
+	*tfo = NULL;
 }
 
 void tfo_close(void **tfo)

Ping. This is a bug fix which seems to have gotten no response.

#2 lore raw
In reply to Stephen Hemminger
Quoted 9 lines · On Wed, 21 May 2025 12:37:27 -0700 Stephen Hemminger…

This was found as error when compiling with LTO. The function allocates new data with rte_zmalloc and then stores pointer in the pointer-to-pointer passed as argument. In the unwind case, it would call rte_free() with wrong one.

Fixes 80317ff6adfd ("net/bnxt/tf_core: support Thor2")

---

Ping. This fixes a real bug why is it being ignored?

In function ‘tfo_open’,
inlined from ‘tfc_open’ at ../drivers/net/bnxt/tf_core/v3/tfc_init.c:34:2,
inlined from ‘ulp_tfc_ctx_attach’ at ../drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c:783:7:
../drivers/net/bnxt/tf_core/v3/tfo.c:108:17: warning: ‘rte_free’ called on pointer ‘bp_44(D)’ with nonzero offset 800 [-Wfree-nonheap-object]

  108 |                 rte_free(tfo);
      |                 ^

In function ‘tfo_open’,
inlined from ‘tfc_open’ at ../drivers/net/bnxt/tf_core/v3/tfc_init.c:34:2,
inlined from ‘ulp_tfc_init’ at ../drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c:957:7:
../drivers/net/bnxt/tf_core/v3/tfo.c:108:17: warning: ‘rte_free’ called on pointer ‘bp_74(D)’ with nonzero offset 800 [-Wfree-nonheap-object]

  108 |                 rte_free(tfo);
      |                 ^