Skip to contentSkip to conversation

net: hinic: Fix warning-hinic_set_vlan_fliter() warn: variable dereferenced before check 'hwdev'

PATCH Superseded Cai Huoqing 2 participants 2 messages Sep 18, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Cai Huoqing

author maintainer
#0 lore raw

PATCH 1/1 net: hinic: Fix warning-hinic_set_vlan_fliter() warn: variable dereferenced before check 'hwdev'

Fix warning, 'hwdev' is checked too late

Fixes 2acf960e3be6 ("net: hinic: Add support for configuration of rx-vlan-filter by ethtool")
---
 drivers/net/ethernet/huawei/hinic/hinic_port.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/huawei/hinic/hinic_port.c +5 -2
index 9406237c461e..bf920c709f82 100644
@@ -450,8 +450,8 @@ int hinic_set_rx_vlan_offload(struct hinic_dev *nic_dev, u8 en)
 int hinic_set_vlan_fliter(struct hinic_dev *nic_dev, u32 en)
 {
 	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;
 	struct hinic_vlan_filter vlan_filter;
 	u16 out_size = sizeof(vlan_filter);
 	int err;
@@ -459,6 +459,9 @@ int hinic_set_vlan_fliter(struct hinic_dev *nic_dev, u32 en)
 	if (!hwdev)
 		return -EINVAL;
 
+	hwif = hwdev->hwif;
+	pdev = hwif->pdev;
+
 	vlan_filter.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
 	vlan_filter.enable = en;
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line · Cai Huoqing

Fix warning, 'hwdev' is checked too late

I cannot find any spot where hwdev will be NULL. Other functions in the driver assume that hwdev points to proper structure always. I believe the proper fix will be to remove redundant check.

Quoted 34 lines
Fixes 2acf960e3be6 ("net: hinic: Add support for configuration of rx-vlan-filter by ethtool")
---
  drivers/net/ethernet/huawei/hinic/hinic_port.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/huawei/hinic/hinic_port.c +5 -2
index 9406237c461e..bf920c709f82 100644
@@ -450,8 +450,8 @@ int hinic_set_rx_vlan_offload(struct hinic_dev *nic_dev, u8 en)
  int hinic_set_vlan_fliter(struct hinic_dev *nic_dev, u32 en)
  {
  	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;
  	struct hinic_vlan_filter vlan_filter;
  	u16 out_size = sizeof(vlan_filter);
  	int err;
@@ -459,6 +459,9 @@ int hinic_set_vlan_fliter(struct hinic_dev *nic_dev, u32 en)
  	if (!hwdev)
  		return -EINVAL;
 
+	hwif = hwdev->hwif;
+	pdev = hwif->pdev;
+
  	vlan_filter.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
  	vlan_filter.enable = en;