Skip to content

Commit b37a466

Browse files
Yajun Dengdavem330
authored andcommitted
netdevice: add the case if dev is NULL
Add the case if dev is NULL in dev_{put, hold}, so the caller doesn't need to care whether dev is NULL or not. Signed-off-by: Yajun Deng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1160dfa commit b37a466

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

include/linux/netdevice.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4143,11 +4143,13 @@ void netdev_run_todo(void);
41434143
*/
41444144
static inline void dev_put(struct net_device *dev)
41454145
{
4146+
if (dev) {
41464147
#ifdef CONFIG_PCPU_DEV_REFCNT
4147-
this_cpu_dec(*dev->pcpu_refcnt);
4148+
this_cpu_dec(*dev->pcpu_refcnt);
41484149
#else
4149-
refcount_dec(&dev->dev_refcnt);
4150+
refcount_dec(&dev->dev_refcnt);
41504151
#endif
4152+
}
41514153
}
41524154

41534155
/**
@@ -4158,11 +4160,13 @@ static inline void dev_put(struct net_device *dev)
41584160
*/
41594161
static inline void dev_hold(struct net_device *dev)
41604162
{
4163+
if (dev) {
41614164
#ifdef CONFIG_PCPU_DEV_REFCNT
4162-
this_cpu_inc(*dev->pcpu_refcnt);
4165+
this_cpu_inc(*dev->pcpu_refcnt);
41634166
#else
4164-
refcount_inc(&dev->dev_refcnt);
4167+
refcount_inc(&dev->dev_refcnt);
41654168
#endif
4169+
}
41664170
}
41674171

41684172
/* Carrier loss detection, dial on demand. The functions netif_carrier_on

0 commit comments

Comments
 (0)