Skip to content

Commit 137e4e1

Browse files
Colin Ian Kingdavem330
authored andcommitted
hinic: fix dereference of pointer hwdev before it is null checked
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 969b15b commit 137e4e1

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

drivers/net/ethernet/huawei/hinic/hinic_port.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,14 +711,17 @@ int hinic_get_rss_type(struct hinic_dev *nic_dev, u32 tmpl_idx,
711711
{
712712
struct hinic_rss_context_table ctx_tbl = { 0 };
713713
struct hinic_hwdev *hwdev = nic_dev->hwdev;
714-
struct hinic_hwif *hwif = hwdev->hwif;
715-
struct pci_dev *pdev = hwif->pdev;
714+
struct hinic_hwif *hwif;
715+
struct pci_dev *pdev;
716716
u16 out_size = sizeof(ctx_tbl);
717717
int err;
718718

719719
if (!hwdev || !rss_type)
720720
return -EINVAL;
721721

722+
hwif = hwdev->hwif;
723+
pdev = hwif->pdev;
724+
722725
ctx_tbl.func_id = HINIC_HWIF_FUNC_IDX(hwif);
723726
ctx_tbl.template_id = tmpl_idx;
724727

@@ -776,14 +779,17 @@ int hinic_rss_get_template_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx,
776779
{
777780
struct hinic_rss_template_key temp_key = { 0 };
778781
struct hinic_hwdev *hwdev = nic_dev->hwdev;
779-
struct hinic_hwif *hwif = hwdev->hwif;
780-
struct pci_dev *pdev = hwif->pdev;
782+
struct hinic_hwif *hwif;
783+
struct pci_dev *pdev;
781784
u16 out_size = sizeof(temp_key);
782785
int err;
783786

784787
if (!hwdev || !temp)
785788
return -EINVAL;
786789

790+
hwif = hwdev->hwif;
791+
pdev = hwif->pdev;
792+
787793
temp_key.func_id = HINIC_HWIF_FUNC_IDX(hwif);
788794
temp_key.template_id = tmpl_idx;
789795

@@ -832,14 +838,17 @@ int hinic_rss_get_hash_engine(struct hinic_dev *nic_dev, u8 tmpl_idx, u8 *type)
832838
{
833839
struct hinic_rss_engine_type hash_type = { 0 };
834840
struct hinic_hwdev *hwdev = nic_dev->hwdev;
835-
struct hinic_hwif *hwif = hwdev->hwif;
836-
struct pci_dev *pdev = hwif->pdev;
841+
struct hinic_hwif *hwif;
842+
struct pci_dev *pdev;
837843
u16 out_size = sizeof(hash_type);
838844
int err;
839845

840846
if (!hwdev || !type)
841847
return -EINVAL;
842848

849+
hwif = hwdev->hwif;
850+
pdev = hwif->pdev;
851+
843852
hash_type.func_id = HINIC_HWIF_FUNC_IDX(hwif);
844853
hash_type.template_id = tmpl_idx;
845854

0 commit comments

Comments
 (0)