[PATCH net] sfc: fix potential memory leak in efx_mae_process_mport()

Abdun Nihaal posted 1 patch 3 months, 2 weeks ago
There is a newer version of this series
drivers/net/ethernet/sfc/mae.c | 1 +
1 file changed, 1 insertion(+)
[PATCH net] sfc: fix potential memory leak in efx_mae_process_mport()
Posted by Abdun Nihaal 3 months, 2 weeks ago
In efx_mae_enumerate_mports(), memory allocated for mae_mport_desc is
passed as a argument to efx_mae_process_mport(), but when the error path
in efx_mae_process_mport() gets executed, the memory allocated for desc
gets leaked.

Fix that by freeing the memory allocation before returning error.

Fixes: a6a15aca4207 ("sfc: enumerate mports in ef100")
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
 drivers/net/ethernet/sfc/mae.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c
index 50f097487b14..15d4af6c1bb9 100644
--- a/drivers/net/ethernet/sfc/mae.c
+++ b/drivers/net/ethernet/sfc/mae.c
@@ -1100,6 +1100,7 @@ static int efx_mae_process_mport(struct efx_nic *efx,
 	if (!IS_ERR_OR_NULL(mport)) {
 		netif_err(efx, drv, efx->net_dev,
 			  "mport with id %u does exist!!!\n", desc->mport_id);
+		kfree(desc);
 		return -EEXIST;
 	}
 
-- 
2.43.0
Re: [PATCH net] sfc: fix potential memory leak in efx_mae_process_mport()
Posted by Edward Cree 3 months, 2 weeks ago
On 22/10/2025 17:35, Abdun Nihaal wrote:
> In efx_mae_enumerate_mports(), memory allocated for mae_mport_desc is
> passed as a argument to efx_mae_process_mport(), but when the error path
> in efx_mae_process_mport() gets executed, the memory allocated for desc
> gets leaked.
> 
> Fix that by freeing the memory allocation before returning error.
> 
> Fixes: a6a15aca4207 ("sfc: enumerate mports in ef100")
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>

Acked-by: Edward Cree <ecree.xilinx@gmail.com>

It might be nice to also add a comment on top of efx_mae_process_mport()
 stating that it takes ownership of @desc from the caller.
Re: [PATCH net] sfc: fix potential memory leak in efx_mae_process_mport()
Posted by Abdun Nihaal 3 months, 2 weeks ago
On Thu, Oct 23, 2025 at 12:27:19PM +0100, Edward Cree wrote:
> Acked-by: Edward Cree <ecree.xilinx@gmail.com>
> 
> It might be nice to also add a comment on top of efx_mae_process_mport()
>  stating that it takes ownership of @desc from the caller.

Sure, I'll add the comment and send a v2 patch.