Skip to content

Commit

Permalink
qlcnic: fix memory leak issues in qlcnic_sriov_common.c
Browse files Browse the repository at this point in the history
Add qlcnic_sriov_free_vlans() in qlcnic_sriov_alloc_vlans() if
any sriov_vlans fails to be allocated.
Add qlcnic_sriov_free_vlans() to free the memory allocated by
qlcnic_sriov_alloc_vlans() if "sriov->allowed_vlans" fails to
be allocated.

Fixes: 91b7282 ("qlcnic: Support VLAN id config.")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
Link: https://patch.msgid.link/20250307094952.14874-1-haoxiang_li2024@163.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Haoxiang Li authored and Paolo Abeni committed Mar 11, 2025
1 parent 415f135 commit d2b9d97
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,10 @@ static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter *adapter,

num_vlans = sriov->num_allowed_vlans;
sriov->allowed_vlans = kcalloc(num_vlans, sizeof(u16), GFP_KERNEL);
if (!sriov->allowed_vlans)
if (!sriov->allowed_vlans) {
qlcnic_sriov_free_vlans(adapter);
return -ENOMEM;
}

vlans = (u16 *)&cmd->rsp.arg[3];
for (i = 0; i < num_vlans; i++)
Expand Down Expand Up @@ -2167,8 +2169,10 @@ int qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *adapter)
vf = &sriov->vf_info[i];
vf->sriov_vlans = kcalloc(sriov->num_allowed_vlans,
sizeof(*vf->sriov_vlans), GFP_KERNEL);
if (!vf->sriov_vlans)
if (!vf->sriov_vlans) {
qlcnic_sriov_free_vlans(adapter);
return -ENOMEM;
}
}

return 0;
Expand Down

0 comments on commit d2b9d97

Please sign in to comment.