Skip to content

Commit d2b9d97

Browse files
Haoxiang LiPaolo Abeni
authored andcommitted
qlcnic: fix memory leak issues in qlcnic_sriov_common.c
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: [email protected] Signed-off-by: Haoxiang Li <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 415f135 commit d2b9d97

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,10 @@ static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter *adapter,
454454

455455
num_vlans = sriov->num_allowed_vlans;
456456
sriov->allowed_vlans = kcalloc(num_vlans, sizeof(u16), GFP_KERNEL);
457-
if (!sriov->allowed_vlans)
457+
if (!sriov->allowed_vlans) {
458+
qlcnic_sriov_free_vlans(adapter);
458459
return -ENOMEM;
460+
}
459461

460462
vlans = (u16 *)&cmd->rsp.arg[3];
461463
for (i = 0; i < num_vlans; i++)
@@ -2167,8 +2169,10 @@ int qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *adapter)
21672169
vf = &sriov->vf_info[i];
21682170
vf->sriov_vlans = kcalloc(sriov->num_allowed_vlans,
21692171
sizeof(*vf->sriov_vlans), GFP_KERNEL);
2170-
if (!vf->sriov_vlans)
2172+
if (!vf->sriov_vlans) {
2173+
qlcnic_sriov_free_vlans(adapter);
21712174
return -ENOMEM;
2175+
}
21722176
}
21732177

21742178
return 0;

0 commit comments

Comments
 (0)