tg3: Avoid NULL pointer dereference in netif_device_attach()
Subsystems (3)
PATCH 1/1 tg3: Avoid NULL pointer dereference in netif_device_attach()
Similar to commit<1b0ff89852d7>("tg3: Avoid NULL pointer dereference in tg3_io_error_detected()") This patch avoids NULL pointer dereference add a check for netdev being NULL on tg3_resume().
--- drivers/net/ethernet/broadcom/tg3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/tg3.c +1 -1
@@ -18099,7 +18099,7 @@ static int tg3_resume(struct device *device)rtnl_lock (); -if (!netif_running (dev)) +if (!netdev || !netif_running (dev)) goto unlock;netif_device_attach (dev);
Signature · 1 line
1.9.1
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Defang,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.9 next-20201016]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Defang-Bo/tg3-Avoid-NULL-pointer-dereference-in-netif_device_attach/20201019-195653 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 7cf726a59435301046250c42131554d9ccc566b8 config: x86_64-randconfig-s022-20201019 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-dirty # https://github.com/0day-ci/linux/commit/3f835547ea4fb78c40a11c129412f724994829fe git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Defang-Bo/tg3-Avoid-NULL-pointer-dereference-in-netif_device_attach/20201019-195653 git checkout 3f835547ea4fb78c40a11c129412f724994829fe # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/net/ethernet/broadcom/tg3.c: In function 'tg3_resume':
>> drivers/net/ethernet/broadcom/tg3.c:18111:7: error: 'netdev' undeclared (first use in this function); did you mean 'net_eq'?
18111 | if (!netdev || !netif_running(dev))
| ^~~~~~
| net_eq drivers/net/ethernet/broadcom/tg3.c:18111:7: note: each undeclared identifier is reported only once for each function it appears in
vim +18111 drivers/net/ethernet/broadcom/tg3.c
18102
18103 static int tg3_resume(struct device *device)
18104 {
18105 struct net_device *dev = dev_get_drvdata(device);
18106 struct tg3 *tp = netdev_priv(dev);
18107 int err = 0;
18108
18109 rtnl_lock();
18110
18111 if (!netdev || !netif_running(dev))
18112 goto unlock;
18113
18114 netif_device_attach(dev);
18115
18116 tg3_full_lock(tp, 0);
18117
18118 tg3_ape_driver_state_change(tp, RESET_KIND_INIT);
18119
18120 tg3_flag_set(tp, INIT_COMPLETE);
18121 err = tg3_restart_hw(tp,
18122 !(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN));
18123 if (err)
18124 goto out;
18125
18126 tg3_timer_start(tp);
18127
18128 tg3_netif_start(tp);
18129
18130 out:
18131 tg3_full_unlock(tp);
18132
18133 if (!err)
18134 tg3_phy_start(tp);
18135
18136 unlock:
18137 rtnl_unlock();
18138 return err;
18139 }
18140 #endif /* CONFIG_PM_SLEEP */
18141
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org