netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tg3: Avoid NULL pointer dereference in netif_device_attach()
@ 2020-10-19 11:22 Defang Bo
  2020-10-19 13:51 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Defang Bo @ 2020-10-19 11:22 UTC (permalink / raw)
  To: siva.kallam, prashant, mchan, davem, kuba; +Cc: netdev, linux-kernel, Defang Bo

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().

Signed-off-by: Defang Bo <bodefang@126.com>
---
 drivers/net/ethernet/broadcom/tg3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index ebff1fc..ae756dd 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -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);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tg3: Avoid NULL pointer dereference in netif_device_attach()
  2020-10-19 11:22 [PATCH] tg3: Avoid NULL pointer dereference in netif_device_attach() Defang Bo
@ 2020-10-19 13:51 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-10-19 13:51 UTC (permalink / raw)
  To: Defang Bo, siva.kallam, prashant, mchan, davem, kuba
  Cc: kbuild-all, netdev, linux-kernel, Defang Bo

[-- Attachment #1: Type: text/plain, Size: 2910 bytes --]

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
Reported-by: kernel test robot <lkp@intel.com>

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@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 40464 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-19 13:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-19 11:22 [PATCH] tg3: Avoid NULL pointer dereference in netif_device_attach() Defang Bo
2020-10-19 13:51 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).