[16/20] net/sfc: fix a memory leak in error handling

Message ID tencent_10003CF1A7A111C93A6DDF4023B222743108@qq.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series fix memory leaks in error handling |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Weiguo Li Feb. 22, 2022, 6:18 p.m. UTC
  When efx_nic_get_board_info() failed then function return, the
memory in 'id' is not released, this leads to a memory leak.

Fixes: e86b48aa46d4 ("net/sfc: add HW switch ID helpers")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/net/sfc/sfc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Andrew Rybchenko March 3, 2022, 7:39 a.m. UTC | #1
On 2/22/22 21:18, Weiguo Li wrote:
> When efx_nic_get_board_info() failed then function return, the
> memory in 'id' is not released, this leads to a memory leak.
> 
> Fixes: e86b48aa46d4 ("net/sfc: add HW switch ID helpers")
> 
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>

Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
  

Patch

diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index 51726d229b..ad1683a512 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -1423,8 +1423,10 @@  sfc_hw_switch_id_init(struct sfc_adapter *sa,
 		return ENOMEM;
 
 	rc = efx_nic_get_board_info(sa->nic, &board_info);
-	if (rc != 0)
+	if (rc != 0) {
+		rte_free(id);
 		return rc;
+	}
 
 	memcpy(id->board_sn, board_info.enbi_serial, sizeof(id->board_sn));