drivers/net/ethernet/huawei/hinic/hinic_port.c:459 hinic_set_vlan_fliter() warn: variable dereferenced before check 'hwdev' (see line 453)

From: Dan Carpenter
Date: Tue Sep 12 2023 - 02:22:08 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
commit: 2acf960e3be6177f437baade6d1883ebe4c641b2 net: hinic: Add support for configuration of rx-vlan-filter by ethtool
config: x86_64-randconfig-161-20230911 (https://download.01.org/0day-ci/archive/20230911/202309112354.pikZCmyk-lkp@xxxxxxxxx/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230911/202309112354.pikZCmyk-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
| Closes: https://lore.kernel.org/r/202309112354.pikZCmyk-lkp@xxxxxxxxx/

smatch warnings:
drivers/net/ethernet/huawei/hinic/hinic_port.c:459 hinic_set_vlan_fliter() warn: variable dereferenced before check 'hwdev' (see line 453)

vim +/hwdev +459 drivers/net/ethernet/huawei/hinic/hinic_port.c

2acf960e3be617 Cai Huoqing 2022-11-03 450 int hinic_set_vlan_fliter(struct hinic_dev *nic_dev, u32 en)
2acf960e3be617 Cai Huoqing 2022-11-03 451 {
2acf960e3be617 Cai Huoqing 2022-11-03 452 struct hinic_hwdev *hwdev = nic_dev->hwdev;
2acf960e3be617 Cai Huoqing 2022-11-03 @453 struct hinic_hwif *hwif = hwdev->hwif;
^^^^^^^
Dereference

2acf960e3be617 Cai Huoqing 2022-11-03 454 struct pci_dev *pdev = hwif->pdev;
2acf960e3be617 Cai Huoqing 2022-11-03 455 struct hinic_vlan_filter vlan_filter;
2acf960e3be617 Cai Huoqing 2022-11-03 456 u16 out_size = sizeof(vlan_filter);
2acf960e3be617 Cai Huoqing 2022-11-03 457 int err;
2acf960e3be617 Cai Huoqing 2022-11-03 458
2acf960e3be617 Cai Huoqing 2022-11-03 @459 if (!hwdev)
^^^^^^
Checked too late.

2acf960e3be617 Cai Huoqing 2022-11-03 460 return -EINVAL;
2acf960e3be617 Cai Huoqing 2022-11-03 461
2acf960e3be617 Cai Huoqing 2022-11-03 462 vlan_filter.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
2acf960e3be617 Cai Huoqing 2022-11-03 463 vlan_filter.enable = en;
2acf960e3be617 Cai Huoqing 2022-11-03 464
2acf960e3be617 Cai Huoqing 2022-11-03 465 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_VLAN_FILTER,

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki