Skip to content

Commit

Permalink
net: Remove redundant if statements
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Yajun Deng authored and davem330 committed Aug 5, 2021
1 parent a85b99a commit 1160dfa
Show file tree
Hide file tree
Showing 39 changed files with 82 additions and 168 deletions.
6 changes: 2 additions & 4 deletions net/batman-adv/bridge_loop_avoidance.c
Original file line number Diff line number Diff line change
Expand Up @@ -2274,8 +2274,7 @@ int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb)
if (primary_if)
batadv_hardif_put(primary_if);

if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

return ret;
}
Expand Down Expand Up @@ -2446,8 +2445,7 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb)
if (primary_if)
batadv_hardif_put(primary_if);

if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions net/batman-adv/distributed-arp-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,7 @@ int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
if (primary_if)
batadv_hardif_put(primary_if);

if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions net/batman-adv/gateway_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,7 @@ int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb)
out:
if (primary_if)
batadv_hardif_put(primary_if);
if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

return ret;
}
Expand Down
9 changes: 3 additions & 6 deletions net/batman-adv/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ static struct net_device *batadv_mcast_get_bridge(struct net_device *soft_iface)
upper = netdev_master_upper_dev_get_rcu(upper);
} while (upper && !(upper->priv_flags & IFF_EBRIDGE));

if (upper)
dev_hold(upper);
dev_hold(upper);
rcu_read_unlock();

return upper;
Expand Down Expand Up @@ -509,8 +508,7 @@ batadv_mcast_mla_softif_get(struct net_device *dev,
}

out:
if (bridge)
dev_put(bridge);
dev_put(bridge);

return ret4 + ret6;
}
Expand Down Expand Up @@ -2239,8 +2237,7 @@ batadv_mcast_netlink_get_primary(struct netlink_callback *cb,
}

out:
if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

if (!ret && primary_if)
*primary_if = hard_iface;
Expand Down
12 changes: 4 additions & 8 deletions net/batman-adv/originator.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,10 @@ int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb)
out:
if (hardif)
batadv_hardif_put(hardif);
if (hard_iface)
dev_put(hard_iface);
dev_put(hard_iface);
if (primary_if)
batadv_hardif_put(primary_if);
if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

return ret;
}
Expand Down Expand Up @@ -1412,12 +1410,10 @@ int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)
out:
if (hardif)
batadv_hardif_put(hardif);
if (hard_iface)
dev_put(hard_iface);
dev_put(hard_iface);
if (primary_if)
batadv_hardif_put(primary_if);
if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

return ret;
}
9 changes: 3 additions & 6 deletions net/batman-adv/translation-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,
out:
if (in_hardif)
batadv_hardif_put(in_hardif);
if (in_dev)
dev_put(in_dev);
dev_put(in_dev);
if (tt_local)
batadv_tt_local_entry_put(tt_local);
if (tt_global)
Expand Down Expand Up @@ -1217,8 +1216,7 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
out:
if (primary_if)
batadv_hardif_put(primary_if);
if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

cb->args[0] = bucket;
cb->args[1] = idx;
Expand Down Expand Up @@ -2005,8 +2003,7 @@ int batadv_tt_global_dump(struct sk_buff *msg, struct netlink_callback *cb)
out:
if (primary_if)
batadv_hardif_put(primary_if);
if (soft_iface)
dev_put(soft_iface);
dev_put(soft_iface);

cb->args[0] = bucket;
cb->args[1] = idx;
Expand Down
8 changes: 2 additions & 6 deletions net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
ro->count = count;

out_fil:
if (dev)
dev_put(dev);

dev_put(dev);
release_sock(sk);
rtnl_unlock();

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

out_err:
if (dev)
dev_put(dev);

dev_put(dev);
release_sock(sk);
rtnl_unlock();

Expand Down
6 changes: 2 additions & 4 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,7 @@ struct net_device *dev_get_by_name(struct net *net, const char *name)

rcu_read_lock();
dev = dev_get_by_name_rcu(net, name);
if (dev)
dev_hold(dev);
dev_hold(dev);
rcu_read_unlock();
return dev;
}
Expand Down Expand Up @@ -905,8 +904,7 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex)

rcu_read_lock();
dev = dev_get_by_index_rcu(net, ifindex);
if (dev)
dev_hold(dev);
dev_hold(dev);
rcu_read_unlock();
return dev;
}
Expand Down
6 changes: 2 additions & 4 deletions net/core/drop_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,7 @@ net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata)
}

hw_metadata->input_dev = metadata->input_dev;
if (hw_metadata->input_dev)
dev_hold(hw_metadata->input_dev);
dev_hold(hw_metadata->input_dev);

return hw_metadata;

Expand All @@ -867,8 +866,7 @@ net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata)
static void
net_dm_hw_metadata_free(const struct devlink_trap_metadata *hw_metadata)
{
if (hw_metadata->input_dev)
dev_put(hw_metadata->input_dev);
dev_put(hw_metadata->input_dev);
kfree(hw_metadata->fa_cookie);
kfree(hw_metadata->trap_name);
kfree(hw_metadata->trap_group_name);
Expand Down
6 changes: 2 additions & 4 deletions net/core/dst.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ void dst_init(struct dst_entry *dst, struct dst_ops *ops,
unsigned short flags)
{
dst->dev = dev;
if (dev)
dev_hold(dev);
dev_hold(dev);
dst->ops = ops;
dst_init_metrics(dst, dst_default_metrics.metrics, true);
dst->expires = 0UL;
Expand Down Expand Up @@ -118,8 +117,7 @@ struct dst_entry *dst_destroy(struct dst_entry * dst)

if (dst->ops->destroy)
dst->ops->destroy(dst);
if (dst->dev)
dev_put(dst->dev);
dev_put(dst->dev);

lwtstate_put(dst->lwtstate);

Expand Down
15 changes: 5 additions & 10 deletions net/core/neighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,10 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,
write_pnet(&n->net, net);
memcpy(n->key, pkey, key_len);
n->dev = dev;
if (dev)
dev_hold(dev);
dev_hold(dev);

if (tbl->pconstructor && tbl->pconstructor(n)) {
if (dev)
dev_put(dev);
dev_put(dev);
kfree(n);
n = NULL;
goto out;
Expand Down Expand Up @@ -778,8 +776,7 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
write_unlock_bh(&tbl->lock);
if (tbl->pdestructor)
tbl->pdestructor(n);
if (n->dev)
dev_put(n->dev);
dev_put(n->dev);
kfree(n);
return 0;
}
Expand Down Expand Up @@ -812,8 +809,7 @@ static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
n->next = NULL;
if (tbl->pdestructor)
tbl->pdestructor(n);
if (n->dev)
dev_put(n->dev);
dev_put(n->dev);
kfree(n);
}
return -ENOENT;
Expand Down Expand Up @@ -1662,8 +1658,7 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)
list_del(&parms->list);
parms->dead = 1;
write_unlock_bh(&tbl->lock);
if (parms->dev)
dev_put(parms->dev);
dev_put(parms->dev);
call_rcu(&parms->rcu_head, neigh_rcu_free_parms);
}
EXPORT_SYMBOL(neigh_parms_release);
Expand Down
6 changes: 2 additions & 4 deletions net/decnet/dn_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,7 @@ int dn_dev_set_default(struct net_device *dev, int force)
}
spin_unlock(&dndev_lock);

if (old)
dev_put(old);
dev_put(old);
return rv;
}

Expand All @@ -536,8 +535,7 @@ static void dn_dev_check_default(struct net_device *dev)
}
spin_unlock(&dndev_lock);

if (dev)
dev_put(dev);
dev_put(dev);
}

/*
Expand Down
3 changes: 1 addition & 2 deletions net/decnet/dn_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ void dn_fib_free_info(struct dn_fib_info *fi)
}

change_nexthops(fi) {
if (nh->nh_dev)
dev_put(nh->nh_dev);
dev_put(nh->nh_dev);
nh->nh_dev = NULL;
} endfor_nexthops(fi);
kfree(fi);
Expand Down
18 changes: 6 additions & 12 deletions net/decnet/dn_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
if (!fld.daddr) {
fld.daddr = fld.saddr;

if (dev_out)
dev_put(dev_out);
dev_put(dev_out);
err = -EINVAL;
dev_out = init_net.loopback_dev;
if (!dev_out->dn_ptr)
Expand Down Expand Up @@ -1084,8 +1083,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
neigh_release(neigh);
neigh = NULL;
} else {
if (dev_out)
dev_put(dev_out);
dev_put(dev_out);
if (dn_dev_islocal(neigh->dev, fld.daddr)) {
dev_out = init_net.loopback_dev;
res.type = RTN_LOCAL;
Expand Down Expand Up @@ -1144,8 +1142,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
if (res.type == RTN_LOCAL) {
if (!fld.saddr)
fld.saddr = fld.daddr;
if (dev_out)
dev_put(dev_out);
dev_put(dev_out);
dev_out = init_net.loopback_dev;
dev_hold(dev_out);
if (!dev_out->dn_ptr)
Expand All @@ -1168,8 +1165,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
if (!fld.saddr)
fld.saddr = DN_FIB_RES_PREFSRC(res);

if (dev_out)
dev_put(dev_out);
dev_put(dev_out);
dev_out = DN_FIB_RES_DEV(res);
dev_hold(dev_out);
fld.flowidn_oif = dev_out->ifindex;
Expand Down Expand Up @@ -1222,8 +1218,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
neigh_release(neigh);
if (free_res)
dn_fib_res_put(&res);
if (dev_out)
dev_put(dev_out);
dev_put(dev_out);
out:
return err;

Expand Down Expand Up @@ -1503,8 +1498,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
if (free_res)
dn_fib_res_put(&res);
dev_put(in_dev);
if (out_dev)
dev_put(out_dev);
dev_put(out_dev);
out:
return err;

Expand Down
6 changes: 2 additions & 4 deletions net/ethtool/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
ops->cleanup_data(reply_data);

genlmsg_end(rskb, reply_payload);
if (req_info->dev)
dev_put(req_info->dev);
dev_put(req_info->dev);
kfree(reply_data);
kfree(req_info);
return genlmsg_reply(rskb, info);
Expand All @@ -411,8 +410,7 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
if (ops->cleanup_data)
ops->cleanup_data(reply_data);
err_dev:
if (req_info->dev)
dev_put(req_info->dev);
dev_put(req_info->dev);
kfree(reply_data);
kfree(req_info);
return ret;
Expand Down
3 changes: 1 addition & 2 deletions net/ieee802154/nl-phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info)
out_dev:
wpan_phy_put(phy);
out:
if (dev)
dev_put(dev);
dev_put(dev);

return rc;
}
3 changes: 1 addition & 2 deletions net/ieee802154/nl802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -2226,8 +2226,7 @@ static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_DEV) {
struct wpan_dev *wpan_dev = info->user_ptr[1];

if (wpan_dev->netdev)
dev_put(wpan_dev->netdev);
dev_put(wpan_dev->netdev);
} else {
dev_put(info->user_ptr[1]);
}
Expand Down
3 changes: 1 addition & 2 deletions net/ieee802154/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ ieee802154_get_dev(struct net *net, const struct ieee802154_addr *addr)
ieee802154_devaddr_to_raw(hwaddr, addr->extended_addr);
rcu_read_lock();
dev = dev_getbyhwaddr_rcu(net, ARPHRD_IEEE802154, hwaddr);
if (dev)
dev_hold(dev);
dev_hold(dev);
rcu_read_unlock();
break;
case IEEE802154_ADDR_SHORT:
Expand Down
Loading

0 comments on commit 1160dfa

Please sign in to comment.