Skip to content

Commit 1160dfa

Browse files
Yajun Dengdavem330
authored andcommitted
net: Remove redundant if statements
The 'if (dev)' statement already move into dev_{put , hold}, so remove redundant if statements. Signed-off-by: Yajun Deng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a85b99a commit 1160dfa

39 files changed

+82
-168
lines changed

net/batman-adv/bridge_loop_avoidance.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,8 +2274,7 @@ int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb)
22742274
if (primary_if)
22752275
batadv_hardif_put(primary_if);
22762276

2277-
if (soft_iface)
2278-
dev_put(soft_iface);
2277+
dev_put(soft_iface);
22792278

22802279
return ret;
22812280
}
@@ -2446,8 +2445,7 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb)
24462445
if (primary_if)
24472446
batadv_hardif_put(primary_if);
24482447

2449-
if (soft_iface)
2450-
dev_put(soft_iface);
2448+
dev_put(soft_iface);
24512449

24522450
return ret;
24532451
}

net/batman-adv/distributed-arp-table.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,7 @@ int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
984984
if (primary_if)
985985
batadv_hardif_put(primary_if);
986986

987-
if (soft_iface)
988-
dev_put(soft_iface);
987+
dev_put(soft_iface);
989988

990989
return ret;
991990
}

net/batman-adv/gateway_client.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,7 @@ int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb)
557557
out:
558558
if (primary_if)
559559
batadv_hardif_put(primary_if);
560-
if (soft_iface)
561-
dev_put(soft_iface);
560+
dev_put(soft_iface);
562561

563562
return ret;
564563
}

net/batman-adv/multicast.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ static struct net_device *batadv_mcast_get_bridge(struct net_device *soft_iface)
9191
upper = netdev_master_upper_dev_get_rcu(upper);
9292
} while (upper && !(upper->priv_flags & IFF_EBRIDGE));
9393

94-
if (upper)
95-
dev_hold(upper);
94+
dev_hold(upper);
9695
rcu_read_unlock();
9796

9897
return upper;
@@ -509,8 +508,7 @@ batadv_mcast_mla_softif_get(struct net_device *dev,
509508
}
510509

511510
out:
512-
if (bridge)
513-
dev_put(bridge);
511+
dev_put(bridge);
514512

515513
return ret4 + ret6;
516514
}
@@ -2239,8 +2237,7 @@ batadv_mcast_netlink_get_primary(struct netlink_callback *cb,
22392237
}
22402238

22412239
out:
2242-
if (soft_iface)
2243-
dev_put(soft_iface);
2240+
dev_put(soft_iface);
22442241

22452242
if (!ret && primary_if)
22462243
*primary_if = hard_iface;

net/batman-adv/originator.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,10 @@ int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb)
799799
out:
800800
if (hardif)
801801
batadv_hardif_put(hardif);
802-
if (hard_iface)
803-
dev_put(hard_iface);
802+
dev_put(hard_iface);
804803
if (primary_if)
805804
batadv_hardif_put(primary_if);
806-
if (soft_iface)
807-
dev_put(soft_iface);
805+
dev_put(soft_iface);
808806

809807
return ret;
810808
}
@@ -1412,12 +1410,10 @@ int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)
14121410
out:
14131411
if (hardif)
14141412
batadv_hardif_put(hardif);
1415-
if (hard_iface)
1416-
dev_put(hard_iface);
1413+
dev_put(hard_iface);
14171414
if (primary_if)
14181415
batadv_hardif_put(primary_if);
1419-
if (soft_iface)
1420-
dev_put(soft_iface);
1416+
dev_put(soft_iface);
14211417

14221418
return ret;
14231419
}

net/batman-adv/translation-table.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,
820820
out:
821821
if (in_hardif)
822822
batadv_hardif_put(in_hardif);
823-
if (in_dev)
824-
dev_put(in_dev);
823+
dev_put(in_dev);
825824
if (tt_local)
826825
batadv_tt_local_entry_put(tt_local);
827826
if (tt_global)
@@ -1217,8 +1216,7 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
12171216
out:
12181217
if (primary_if)
12191218
batadv_hardif_put(primary_if);
1220-
if (soft_iface)
1221-
dev_put(soft_iface);
1219+
dev_put(soft_iface);
12221220

12231221
cb->args[0] = bucket;
12241222
cb->args[1] = idx;
@@ -2005,8 +2003,7 @@ int batadv_tt_global_dump(struct sk_buff *msg, struct netlink_callback *cb)
20052003
out:
20062004
if (primary_if)
20072005
batadv_hardif_put(primary_if);
2008-
if (soft_iface)
2009-
dev_put(soft_iface);
2006+
dev_put(soft_iface);
20102007

20112008
cb->args[0] = bucket;
20122009
cb->args[1] = idx;

net/can/raw.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
592592
ro->count = count;
593593

594594
out_fil:
595-
if (dev)
596-
dev_put(dev);
597-
595+
dev_put(dev);
598596
release_sock(sk);
599597
rtnl_unlock();
600598

@@ -638,9 +636,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
638636
ro->err_mask = err_mask;
639637

640638
out_err:
641-
if (dev)
642-
dev_put(dev);
643-
639+
dev_put(dev);
644640
release_sock(sk);
645641
rtnl_unlock();
646642

net/core/dev.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,7 @@ struct net_device *dev_get_by_name(struct net *net, const char *name)
831831

832832
rcu_read_lock();
833833
dev = dev_get_by_name_rcu(net, name);
834-
if (dev)
835-
dev_hold(dev);
834+
dev_hold(dev);
836835
rcu_read_unlock();
837836
return dev;
838837
}
@@ -905,8 +904,7 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex)
905904

906905
rcu_read_lock();
907906
dev = dev_get_by_index_rcu(net, ifindex);
908-
if (dev)
909-
dev_hold(dev);
907+
dev_hold(dev);
910908
rcu_read_unlock();
911909
return dev;
912910
}

net/core/drop_monitor.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,7 @@ net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata)
850850
}
851851

852852
hw_metadata->input_dev = metadata->input_dev;
853-
if (hw_metadata->input_dev)
854-
dev_hold(hw_metadata->input_dev);
853+
dev_hold(hw_metadata->input_dev);
855854

856855
return hw_metadata;
857856

@@ -867,8 +866,7 @@ net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata)
867866
static void
868867
net_dm_hw_metadata_free(const struct devlink_trap_metadata *hw_metadata)
869868
{
870-
if (hw_metadata->input_dev)
871-
dev_put(hw_metadata->input_dev);
869+
dev_put(hw_metadata->input_dev);
872870
kfree(hw_metadata->fa_cookie);
873871
kfree(hw_metadata->trap_name);
874872
kfree(hw_metadata->trap_group_name);

net/core/dst.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ void dst_init(struct dst_entry *dst, struct dst_ops *ops,
4949
unsigned short flags)
5050
{
5151
dst->dev = dev;
52-
if (dev)
53-
dev_hold(dev);
52+
dev_hold(dev);
5453
dst->ops = ops;
5554
dst_init_metrics(dst, dst_default_metrics.metrics, true);
5655
dst->expires = 0UL;
@@ -118,8 +117,7 @@ struct dst_entry *dst_destroy(struct dst_entry * dst)
118117

119118
if (dst->ops->destroy)
120119
dst->ops->destroy(dst);
121-
if (dst->dev)
122-
dev_put(dst->dev);
120+
dev_put(dst->dev);
123121

124122
lwtstate_put(dst->lwtstate);
125123

0 commit comments

Comments
 (0)