Skip to contentSkip to conversation

qlcnic: fix memory leak in qlcnic_sriov_channel_cfg_cmd()

PATCH Applied Abdun Nihaal 3 participants 3 messages May 12, 2025 – May 14, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qlcnic: fix memory leak in qlcnic_sriov_channel_cfg_cmd()

In one of the error paths in qlcnic_sriov_channel_cfg_cmd(), the memory allocated in qlcnic_sriov_alloc_bc_mbx_args() for mailbox arguments is not freed. Fix that by jumping to the error path that frees them, by calling qlcnic_free_mbx_args(). This was found using static analysis.

Fixes f197a7aa6288 ("qlcnic: VF-PF communication channel implementation")

---
This patch is only compile tested. Not tested on real hardware.

V1->V2 : Added information about how the bug was found and how the patch was tested, as suggested by Simon Horman.

 drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c +5 -2
index 28d24d59efb8..d57b976b9040 100644
@@ -1484,8 +1484,11 @@ static int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter *adapter, u8 cmd_o
 	}
 
 	cmd_op = (cmd.rsp.arg[0] & 0xff);
-	if (cmd.rsp.arg[0] >> 25 == 2)
-		return 2;
+	if (cmd.rsp.arg[0] >> 25 == 2) {
+		ret = 2;
+		goto out;
+	}
+
 	if (cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT)
 		set_bit(QLC_BC_VF_STATE, &vf->state);
 	else
Signature · 1 line
2.47.2
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Abdun Nihaal

In one of the error paths in qlcnic_sriov_channel_cfg_cmd(), the memory allocated in qlcnic_sriov_alloc_bc_mbx_args() for mailbox arguments is not freed. Fix that by jumping to the error path that frees them, by calling qlcnic_free_mbx_args(). This was found using static analysis.

Fixes f197a7aa6288 ("qlcnic: VF-PF communication channel implementation")
Quoted 8 lines

---
This patch is only compile tested. Not tested on real hardware.

V1->V2 : Added information about how the bug was found and how the patch was tested, as suggested by Simon Horman.

 drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Thanks for the update.

#2 lore raw
In reply to Abdun Nihaal
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 12 May 2025 10:18:27 +0530 you wrote:

In one of the error paths in qlcnic_sriov_channel_cfg_cmd(), the memory allocated in qlcnic_sriov_alloc_bc_mbx_args() for mailbox arguments is not freed. Fix that by jumping to the error path that frees them, by calling qlcnic_free_mbx_args(). This was found using static analysis.

Fixes f197a7aa6288 ("qlcnic: VF-PF communication channel implementation")

[...]

Here is the summary with links:
- [net,v2] qlcnic: fix memory leak in qlcnic_sriov_channel_cfg_cmd()

    https://git.kernel.org/netdev/net/c/9d8a99c5a7c7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html