drivers/net/ethernet/intel/ice/ice_main.c:789 ice_set_dflt_mib() warn: variable dereferenced before check 'pf' (see line 782)

From: Dan Carpenter
Date: Wed Oct 07 2020 - 04:22:40 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 22fbc037cd32e4e6771d2271b565806cfb8c134c
commit: 7d9c9b791f9e275b49870b6b10a1ea4d49209de8 ice: Implement LFC workaround
config: x86_64-randconfig-m001-20201003 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
drivers/net/ethernet/intel/ice/ice_main.c:789 ice_set_dflt_mib() warn: variable dereferenced before check 'pf' (see line 782)

vim +/pf +789 drivers/net/ethernet/intel/ice/ice_main.c

7d9c9b791f9e275 Dave Ertman 2020-07-13 780 static void ice_set_dflt_mib(struct ice_pf *pf)
7d9c9b791f9e275 Dave Ertman 2020-07-13 781 {
7d9c9b791f9e275 Dave Ertman 2020-07-13 @782 struct device *dev = ice_pf_to_dev(pf);
^^
Derferenced

7d9c9b791f9e275 Dave Ertman 2020-07-13 783 u8 mib_type, *buf, *lldpmib = NULL;
7d9c9b791f9e275 Dave Ertman 2020-07-13 784 u16 len, typelen, offset = 0;
7d9c9b791f9e275 Dave Ertman 2020-07-13 785 struct ice_lldp_org_tlv *tlv;
7d9c9b791f9e275 Dave Ertman 2020-07-13 786 struct ice_hw *hw;
7d9c9b791f9e275 Dave Ertman 2020-07-13 787 u32 ouisubtype;
7d9c9b791f9e275 Dave Ertman 2020-07-13 788
7d9c9b791f9e275 Dave Ertman 2020-07-13 @789 if (!pf) {
^^^
Checked too late.

7d9c9b791f9e275 Dave Ertman 2020-07-13 790 dev_dbg(dev, "%s NULL pf pointer\n", __func__);
7d9c9b791f9e275 Dave Ertman 2020-07-13 791 return;
7d9c9b791f9e275 Dave Ertman 2020-07-13 792 }
7d9c9b791f9e275 Dave Ertman 2020-07-13 793
7d9c9b791f9e275 Dave Ertman 2020-07-13 794 hw = &pf->hw;
7d9c9b791f9e275 Dave Ertman 2020-07-13 795 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
7d9c9b791f9e275 Dave Ertman 2020-07-13 796 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL);
7d9c9b791f9e275 Dave Ertman 2020-07-13 797 if (!lldpmib) {

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip