]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
sfc: fix potential memory leak in efx_mae_process_mport()
authorAbdun Nihaal <nihaal@cse.iitm.ac.in>
Thu, 23 Oct 2025 14:18:42 +0000 (19:48 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:33:59 +0000 (15:33 -0500)
[ Upstream commit 46a499aaf8c27476fd05e800f3e947bfd71aa724 ]

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")
Acked-by: Edward Cree <ecree.xilinx@gmail.com>
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
Link: https://patch.msgid.link/20251023141844.25847-1-nihaal@cse.iitm.ac.in
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/sfc/mae.c

index 10709d828a636d23a448bb61cc414826ee7a12dc..21d559646073211f9e0723ea3a56982792acdbf3 100644 (file)
@@ -1101,6 +1101,9 @@ void efx_mae_remove_mport(void *desc, void *arg)
        kfree(mport);
 }
 
+/*
+ * Takes ownership of @desc, even if it returns an error
+ */
 static int efx_mae_process_mport(struct efx_nic *efx,
                                 struct mae_mport_desc *desc)
 {
@@ -1111,6 +1114,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;
        }