Skip to content

Commit

Permalink
hinic: fix dereference of pointer hwdev before it is null checked
Browse files Browse the repository at this point in the history
Currently pointer hwdev is dereferenced when assigning hwif before
hwdev is null checked.  Fix this by only derefencing hwdev after the
null check.

Addresses-Coverity: ("Dereference before null check")
Fixes: 4fdc51b ("hinic: add support for rss parameters with ethtool")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Colin Ian King authored and David S. Miller committed Jun 23, 2019
1 parent 969b15b commit 137e4e1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions drivers/net/ethernet/huawei/hinic/hinic_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,17 @@ int hinic_get_rss_type(struct hinic_dev *nic_dev, u32 tmpl_idx,
{
struct hinic_rss_context_table ctx_tbl = { 0 };
struct hinic_hwdev *hwdev = nic_dev->hwdev;
struct hinic_hwif *hwif = hwdev->hwif;
struct pci_dev *pdev = hwif->pdev;
struct hinic_hwif *hwif;
struct pci_dev *pdev;
u16 out_size = sizeof(ctx_tbl);
int err;

if (!hwdev || !rss_type)
return -EINVAL;

hwif = hwdev->hwif;
pdev = hwif->pdev;

ctx_tbl.func_id = HINIC_HWIF_FUNC_IDX(hwif);
ctx_tbl.template_id = tmpl_idx;

Expand Down Expand Up @@ -776,14 +779,17 @@ int hinic_rss_get_template_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx,
{
struct hinic_rss_template_key temp_key = { 0 };
struct hinic_hwdev *hwdev = nic_dev->hwdev;
struct hinic_hwif *hwif = hwdev->hwif;
struct pci_dev *pdev = hwif->pdev;
struct hinic_hwif *hwif;
struct pci_dev *pdev;
u16 out_size = sizeof(temp_key);
int err;

if (!hwdev || !temp)
return -EINVAL;

hwif = hwdev->hwif;
pdev = hwif->pdev;

temp_key.func_id = HINIC_HWIF_FUNC_IDX(hwif);
temp_key.template_id = tmpl_idx;

Expand Down Expand Up @@ -832,14 +838,17 @@ int hinic_rss_get_hash_engine(struct hinic_dev *nic_dev, u8 tmpl_idx, u8 *type)
{
struct hinic_rss_engine_type hash_type = { 0 };
struct hinic_hwdev *hwdev = nic_dev->hwdev;
struct hinic_hwif *hwif = hwdev->hwif;
struct pci_dev *pdev = hwif->pdev;
struct hinic_hwif *hwif;
struct pci_dev *pdev;
u16 out_size = sizeof(hash_type);
int err;

if (!hwdev || !type)
return -EINVAL;

hwif = hwdev->hwif;
pdev = hwif->pdev;

hash_type.func_id = HINIC_HWIF_FUNC_IDX(hwif);
hash_type.template_id = tmpl_idx;

Expand Down

0 comments on commit 137e4e1

Please sign in to comment.