Skip to content

Commit

Permalink
batman-adv: Drop NULL check before dropping references
Browse files Browse the repository at this point in the history
The check if a batman-adv related object is NULL or not is now directly in
the batadv_*_put functions. It is not needed anymore to perform this check
outside these function:

The changes were generated using a coccinelle semantic patch:

  @@
  expression E;
  @@
  - if (likely(E != NULL))
  (
  batadv_backbone_gw_put
  |
  batadv_claim_put
  |
  batadv_dat_entry_put
  |
  batadv_gw_node_put
  |
  batadv_hardif_neigh_put
  |
  batadv_hardif_put
  |
  batadv_nc_node_put
  |
  batadv_nc_path_put
  |
  batadv_neigh_ifinfo_put
  |
  batadv_neigh_node_put
  |
  batadv_orig_ifinfo_put
  |
  batadv_orig_node_put
  |
  batadv_orig_node_vlan_put
  |
  batadv_softif_vlan_put
  |
  batadv_tp_vars_put
  |
  batadv_tt_global_entry_put
  |
  batadv_tt_local_entry_put
  |
  batadv_tt_orig_list_entry_put
  |
  batadv_tt_req_node_put
  |
  batadv_tvlv_container_put
  |
  batadv_tvlv_handler_put
  )(E);

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
  • Loading branch information
ecsv authored and simonwunderlich committed Aug 8, 2021
1 parent 6340dcb commit 79a0bff
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 337 deletions.
75 changes: 25 additions & 50 deletions net/batman-adv/bat_iv_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,
}

out:
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);
return res;
}

Expand Down Expand Up @@ -857,8 +856,7 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
rcu_read_unlock();

out:
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);
}

static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
Expand Down Expand Up @@ -1046,14 +1044,10 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
unlock:
rcu_read_unlock();
out:
if (neigh_node)
batadv_neigh_node_put(neigh_node);
if (router)
batadv_neigh_node_put(router);
if (neigh_ifinfo)
batadv_neigh_ifinfo_put(neigh_ifinfo);
if (router_ifinfo)
batadv_neigh_ifinfo_put(router_ifinfo);
batadv_neigh_node_put(neigh_node);
batadv_neigh_node_put(router);
batadv_neigh_ifinfo_put(neigh_ifinfo);
batadv_neigh_ifinfo_put(router_ifinfo);
}

/**
Expand Down Expand Up @@ -1194,8 +1188,7 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
ret = true;

out:
if (neigh_node)
batadv_neigh_node_put(neigh_node);
batadv_neigh_node_put(neigh_node);
return ret;
}

Expand Down Expand Up @@ -1496,16 +1489,11 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
if (orig_neigh_node && !is_single_hop_neigh)
batadv_orig_node_put(orig_neigh_node);
out:
if (router_ifinfo)
batadv_neigh_ifinfo_put(router_ifinfo);
if (router)
batadv_neigh_node_put(router);
if (router_router)
batadv_neigh_node_put(router_router);
if (orig_neigh_router)
batadv_neigh_node_put(orig_neigh_router);
if (hardif_neigh)
batadv_hardif_neigh_put(hardif_neigh);
batadv_neigh_ifinfo_put(router_ifinfo);
batadv_neigh_node_put(router);
batadv_neigh_node_put(router_router);
batadv_neigh_node_put(orig_neigh_router);
batadv_hardif_neigh_put(hardif_neigh);

consume_skb(skb_priv);
}
Expand Down Expand Up @@ -1926,8 +1914,7 @@ batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
}

out:
if (neigh_node_best)
batadv_neigh_node_put(neigh_node_best);
batadv_neigh_node_put(neigh_node_best);

*sub_s = 0;
return 0;
Expand Down Expand Up @@ -2049,10 +2036,8 @@ static bool batadv_iv_ogm_neigh_diff(struct batadv_neigh_node *neigh1,
*diff = (int)tq1 - (int)tq2;

out:
if (neigh1_ifinfo)
batadv_neigh_ifinfo_put(neigh1_ifinfo);
if (neigh2_ifinfo)
batadv_neigh_ifinfo_put(neigh2_ifinfo);
batadv_neigh_ifinfo_put(neigh1_ifinfo);
batadv_neigh_ifinfo_put(neigh2_ifinfo);

return ret;
}
Expand Down Expand Up @@ -2299,8 +2284,7 @@ batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
if (tmp_gw_factor > max_gw_factor ||
(tmp_gw_factor == max_gw_factor &&
tq_avg > max_tq)) {
if (curr_gw)
batadv_gw_node_put(curr_gw);
batadv_gw_node_put(curr_gw);
curr_gw = gw_node;
kref_get(&curr_gw->refcount);
}
Expand All @@ -2314,8 +2298,7 @@ batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
* $routing_class more tq points)
*/
if (tq_avg > max_tq) {
if (curr_gw)
batadv_gw_node_put(curr_gw);
batadv_gw_node_put(curr_gw);
curr_gw = gw_node;
kref_get(&curr_gw->refcount);
}
Expand All @@ -2332,8 +2315,7 @@ batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)

next:
batadv_neigh_node_put(router);
if (router_ifinfo)
batadv_neigh_ifinfo_put(router_ifinfo);
batadv_neigh_ifinfo_put(router_ifinfo);
}
rcu_read_unlock();

Expand Down Expand Up @@ -2397,14 +2379,10 @@ static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,

ret = true;
out:
if (router_gw_ifinfo)
batadv_neigh_ifinfo_put(router_gw_ifinfo);
if (router_orig_ifinfo)
batadv_neigh_ifinfo_put(router_orig_ifinfo);
if (router_gw)
batadv_neigh_node_put(router_gw);
if (router_orig)
batadv_neigh_node_put(router_orig);
batadv_neigh_ifinfo_put(router_gw_ifinfo);
batadv_neigh_ifinfo_put(router_orig_ifinfo);
batadv_neigh_node_put(router_gw);
batadv_neigh_node_put(router_orig);

return ret;
}
Expand Down Expand Up @@ -2479,12 +2457,9 @@ static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid,
ret = 0;

out:
if (curr_gw)
batadv_gw_node_put(curr_gw);
if (router_ifinfo)
batadv_neigh_ifinfo_put(router_ifinfo);
if (router)
batadv_neigh_node_put(router);
batadv_gw_node_put(curr_gw);
batadv_neigh_ifinfo_put(router_ifinfo);
batadv_neigh_node_put(router);
return ret;
}

Expand Down
30 changes: 10 additions & 20 deletions net/batman-adv/bat_v.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface)

batadv_v_primary_iface_set(hard_iface);
out:
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);
}

static void
Expand Down Expand Up @@ -366,8 +365,7 @@ batadv_v_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
}

out:
if (neigh_node_best)
batadv_neigh_node_put(neigh_node_best);
batadv_neigh_node_put(neigh_node_best);

*sub_s = 0;
return 0;
Expand Down Expand Up @@ -568,10 +566,8 @@ static int batadv_v_gw_throughput_get(struct batadv_gw_node *gw_node, u32 *bw)

ret = 0;
out:
if (router)
batadv_neigh_node_put(router);
if (router_ifinfo)
batadv_neigh_ifinfo_put(router_ifinfo);
batadv_neigh_node_put(router);
batadv_neigh_ifinfo_put(router_ifinfo);

return ret;
}
Expand Down Expand Up @@ -599,8 +595,7 @@ batadv_v_gw_get_best_gw_node(struct batadv_priv *bat_priv)
if (curr_gw && bw <= max_bw)
goto next;

if (curr_gw)
batadv_gw_node_put(curr_gw);
batadv_gw_node_put(curr_gw);

curr_gw = gw_node;
kref_get(&curr_gw->refcount);
Expand Down Expand Up @@ -662,10 +657,8 @@ static bool batadv_v_gw_is_eligible(struct batadv_priv *bat_priv,

ret = true;
out:
if (curr_gw)
batadv_gw_node_put(curr_gw);
if (orig_gw)
batadv_gw_node_put(orig_gw);
batadv_gw_node_put(curr_gw);
batadv_gw_node_put(orig_gw);

return ret;
}
Expand Down Expand Up @@ -764,12 +757,9 @@ static int batadv_v_gw_dump_entry(struct sk_buff *msg, u32 portid,
ret = 0;

out:
if (curr_gw)
batadv_gw_node_put(curr_gw);
if (router_ifinfo)
batadv_neigh_ifinfo_put(router_ifinfo);
if (router)
batadv_neigh_node_put(router);
batadv_gw_node_put(curr_gw);
batadv_neigh_ifinfo_put(router_ifinfo);
batadv_neigh_node_put(router);
return ret;
}

Expand Down
9 changes: 3 additions & 6 deletions net/batman-adv/bat_v_elp.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,11 @@ static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,
hardif_neigh->bat_v.elp_interval = ntohl(elp_packet->elp_interval);

hardif_free:
if (hardif_neigh)
batadv_hardif_neigh_put(hardif_neigh);
batadv_hardif_neigh_put(hardif_neigh);
neigh_free:
if (neigh)
batadv_neigh_node_put(neigh);
batadv_neigh_node_put(neigh);
orig_free:
if (orig_neigh)
batadv_orig_node_put(orig_neigh);
batadv_orig_node_put(orig_neigh);
}

/**
Expand Down
39 changes: 13 additions & 26 deletions net/batman-adv/bat_v_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,9 @@ static void batadv_v_ogm_forward(struct batadv_priv *bat_priv,
batadv_v_ogm_queue_on_if(skb, if_outgoing);

out:
if (orig_ifinfo)
batadv_orig_ifinfo_put(orig_ifinfo);
if (router)
batadv_neigh_node_put(router);
if (neigh_ifinfo)
batadv_neigh_ifinfo_put(neigh_ifinfo);
batadv_orig_ifinfo_put(orig_ifinfo);
batadv_neigh_node_put(router);
batadv_neigh_ifinfo_put(neigh_ifinfo);
}

/**
Expand Down Expand Up @@ -669,10 +666,8 @@ static int batadv_v_ogm_metric_update(struct batadv_priv *bat_priv,
else
ret = 0;
out:
if (orig_ifinfo)
batadv_orig_ifinfo_put(orig_ifinfo);
if (neigh_ifinfo)
batadv_neigh_ifinfo_put(neigh_ifinfo);
batadv_orig_ifinfo_put(orig_ifinfo);
batadv_neigh_ifinfo_put(neigh_ifinfo);

return ret;
}
Expand Down Expand Up @@ -763,16 +758,11 @@ static bool batadv_v_ogm_route_update(struct batadv_priv *bat_priv,

batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node);
out:
if (router)
batadv_neigh_node_put(router);
if (orig_neigh_router)
batadv_neigh_node_put(orig_neigh_router);
if (orig_neigh_node)
batadv_orig_node_put(orig_neigh_node);
if (router_ifinfo)
batadv_neigh_ifinfo_put(router_ifinfo);
if (neigh_ifinfo)
batadv_neigh_ifinfo_put(neigh_ifinfo);
batadv_neigh_node_put(router);
batadv_neigh_node_put(orig_neigh_router);
batadv_orig_node_put(orig_neigh_node);
batadv_neigh_ifinfo_put(router_ifinfo);
batadv_neigh_ifinfo_put(neigh_ifinfo);

return forward;
}
Expand Down Expand Up @@ -978,12 +968,9 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
}
rcu_read_unlock();
out:
if (orig_node)
batadv_orig_node_put(orig_node);
if (neigh_node)
batadv_neigh_node_put(neigh_node);
if (hardif_neigh)
batadv_hardif_neigh_put(hardif_neigh);
batadv_orig_node_put(orig_node);
batadv_neigh_node_put(neigh_node);
batadv_hardif_neigh_put(hardif_neigh);
}

/**
Expand Down
27 changes: 9 additions & 18 deletions net/batman-adv/bridge_loop_avoidance.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,

netif_rx_any_context(skb);
out:
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);
}

/**
Expand Down Expand Up @@ -1504,8 +1503,7 @@ static void batadv_bla_periodic_work(struct work_struct *work)
rcu_read_unlock();
}
out:
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);

queue_delayed_work(batadv_event_workqueue, &bat_priv->bla.work,
msecs_to_jiffies(BATADV_BLA_PERIOD_LENGTH));
Expand Down Expand Up @@ -1814,8 +1812,7 @@ void batadv_bla_free(struct batadv_priv *bat_priv)
batadv_hash_destroy(bat_priv->bla.backbone_hash);
bat_priv->bla.backbone_hash = NULL;
}
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);
}

/**
Expand Down Expand Up @@ -2002,10 +1999,8 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
ret = true;

out:
if (primary_if)
batadv_hardif_put(primary_if);
if (claim)
batadv_claim_put(claim);
batadv_hardif_put(primary_if);
batadv_claim_put(claim);
return ret;
}

Expand Down Expand Up @@ -2109,10 +2104,8 @@ bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
handled:
ret = true;
out:
if (primary_if)
batadv_hardif_put(primary_if);
if (claim)
batadv_claim_put(claim);
batadv_hardif_put(primary_if);
batadv_claim_put(claim);
return ret;
}

Expand Down Expand Up @@ -2277,8 +2270,7 @@ int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb)
ret = msg->len;

out:
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);

dev_put(soft_iface);

Expand Down Expand Up @@ -2448,8 +2440,7 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb)
ret = msg->len;

out:
if (primary_if)
batadv_hardif_put(primary_if);
batadv_hardif_put(primary_if);

dev_put(soft_iface);

Expand Down
Loading

0 comments on commit 79a0bff

Please sign in to comment.