Skip to content

Commit

Permalink
qlcnic: potential dereference null pointer of rx_queue->page_ring
Browse files Browse the repository at this point in the history
[ Upstream commit 60ec7fc ]

The return value of kcalloc() needs to be checked.
To avoid dereference of null pointer in case of the failure of alloc.
Therefore, it might be better to change the return type of
qlcnic_sriov_alloc_vlans() and return -ENOMEM when alloc fails and
return 0 the others.
Also, qlcnic_sriov_set_guest_vlan_mode() and __qlcnic_pci_sriov_enable()
should deal with the return value of qlcnic_sriov_alloc_vlans().

Fixes: 154d0c8 ("qlcnic: VLAN enhancement for 84XX adapters")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
JiangJias authored and gregkh committed Dec 29, 2021
1 parent 5c553a0 commit e69eacf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov.h
Expand Up @@ -201,7 +201,7 @@ int qlcnic_sriov_get_vf_vport_info(struct qlcnic_adapter *,
struct qlcnic_info *, u16);
int qlcnic_sriov_cfg_vf_guest_vlan(struct qlcnic_adapter *, u16, u8);
void qlcnic_sriov_free_vlans(struct qlcnic_adapter *);
void qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *);
int qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *);
bool qlcnic_sriov_check_any_vlan(struct qlcnic_vf_info *);
void qlcnic_sriov_del_vlan_id(struct qlcnic_sriov *,
struct qlcnic_vf_info *, u16);
Expand Down
12 changes: 9 additions & 3 deletions drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
Expand Up @@ -432,7 +432,7 @@ static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter *adapter,
struct qlcnic_cmd_args *cmd)
{
struct qlcnic_sriov *sriov = adapter->ahw->sriov;
int i, num_vlans;
int i, num_vlans, ret;
u16 *vlans;

if (sriov->allowed_vlans)
Expand All @@ -443,7 +443,9 @@ static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter *adapter,
dev_info(&adapter->pdev->dev, "Number of allowed Guest VLANs = %d\n",
sriov->num_allowed_vlans);

qlcnic_sriov_alloc_vlans(adapter);
ret = qlcnic_sriov_alloc_vlans(adapter);
if (ret)
return ret;

if (!sriov->any_vlan)
return 0;
Expand Down Expand Up @@ -2154,7 +2156,7 @@ static int qlcnic_sriov_vf_resume(struct qlcnic_adapter *adapter)
return err;
}

void qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *adapter)
int qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *adapter)
{
struct qlcnic_sriov *sriov = adapter->ahw->sriov;
struct qlcnic_vf_info *vf;
Expand All @@ -2164,7 +2166,11 @@ void 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)
return -ENOMEM;
}

return 0;
}

void qlcnic_sriov_free_vlans(struct qlcnic_adapter *adapter)
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
Expand Up @@ -597,7 +597,9 @@ static int __qlcnic_pci_sriov_enable(struct qlcnic_adapter *adapter,
if (err)
goto del_flr_queue;

qlcnic_sriov_alloc_vlans(adapter);
err = qlcnic_sriov_alloc_vlans(adapter);
if (err)
goto del_flr_queue;

return err;

Expand Down

0 comments on commit e69eacf

Please sign in to comment.