drivers/net/wireless/mediatek/mt76/mt7996/main.c:73 mt7996_stop_phy() warn: variable dereferenced before check 'phy' (see line 71)

From: Dan Carpenter
Date: Sat Feb 01 2025 - 01:57:07 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: fd8c09ad0d87783b9b6a27900d66293be45b7bad
commit: 69d54ce7491d046eaae05de7fb2493319a481991 wifi: mt76: mt7996: switch to single multi-radio wiphy
config: alpha-randconfig-r071-20250131 (https://download.01.org/0day-ci/archive/20250201/202502010604.nBhFqzvE-lkp@xxxxxxxxx/config)
compiler: alpha-linux-gcc (GCC) 14.2.0

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/202502010604.nBhFqzvE-lkp@xxxxxxxxx/

smatch warnings:
drivers/net/wireless/mediatek/mt76/mt7996/main.c:73 mt7996_stop_phy() warn: variable dereferenced before check 'phy' (see line 71)
drivers/net/wireless/mediatek/mt76/mt7996/main.c:357 mt7996_set_monitor() warn: variable dereferenced before check 'phy' (see line 355)

vim +/phy +73 drivers/net/wireless/mediatek/mt76/mt7996/main.c

69d54ce7491d046 Felix Fietkau 2025-01-02 69 static void mt7996_stop_phy(struct mt7996_phy *phy)
98686cd21624c75 Shayne Chen 2022-11-22 70 {
69d54ce7491d046 Felix Fietkau 2025-01-02 @71 struct mt7996_dev *dev = phy->dev;
^^^^^^^^
Dereference

69d54ce7491d046 Felix Fietkau 2025-01-02 72
69d54ce7491d046 Felix Fietkau 2025-01-02 @73 if (!phy || !test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
^^^
Checked too late

69d54ce7491d046 Felix Fietkau 2025-01-02 74 return;
98686cd21624c75 Shayne Chen 2022-11-22 75
98686cd21624c75 Shayne Chen 2022-11-22 76 cancel_delayed_work_sync(&phy->mt76->mac_work);
98686cd21624c75 Shayne Chen 2022-11-22 77
98686cd21624c75 Shayne Chen 2022-11-22 78 mutex_lock(&dev->mt76.mutex);
98686cd21624c75 Shayne Chen 2022-11-22 79
d73dab22e7a8a8f Shayne Chen 2023-06-05 80 mt7996_mcu_set_radio_en(phy, false);
d73dab22e7a8a8f Shayne Chen 2023-06-05 81
98686cd21624c75 Shayne Chen 2022-11-22 82 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
98686cd21624c75 Shayne Chen 2022-11-22 83
98686cd21624c75 Shayne Chen 2022-11-22 84 mutex_unlock(&dev->mt76.mutex);
98686cd21624c75 Shayne Chen 2022-11-22 85 }

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