batman-adv: use rcu_replace_pointer() where appropriate
authorAntonio Quartulli <a@unstable.cc>
Wed, 20 May 2020 08:41:40 +0000 (10:41 +0200)
committerSimon Wunderlich <sw@simonwunderlich.de>
Fri, 22 May 2020 12:19:24 +0000 (14:19 +0200)
In commit a63fc6b75cca ("rcu: Upgrade rcu_swap_protected() to
rcu_replace_pointer()") a new helper macro named rcu_replace_pointer() was
introduced to simplify code requiring to switch an rcu pointer to a new
value while extracting the old one.

Use rcu_replace_pointer() where appropriate to make code slimer.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
net/batman-adv/gateway_client.c
net/batman-adv/hard-interface.c
net/batman-adv/routing.c

index e22e492..a18dcc6 100644 (file)
@@ -146,8 +146,8 @@ static void batadv_gw_select(struct batadv_priv *bat_priv,
        if (new_gw_node)
                kref_get(&new_gw_node->refcount);
 
-       curr_gw_node = rcu_dereference_protected(bat_priv->gw.curr_gw, 1);
-       rcu_assign_pointer(bat_priv->gw.curr_gw, new_gw_node);
+       curr_gw_node = rcu_replace_pointer(bat_priv->gw.curr_gw, new_gw_node,
+                                          true);
 
        if (curr_gw_node)
                batadv_gw_node_put(curr_gw_node);
index c7e98a4..3a256af 100644 (file)
@@ -473,8 +473,8 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv,
        if (new_hard_iface)
                kref_get(&new_hard_iface->refcount);
 
-       curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
-       rcu_assign_pointer(bat_priv->primary_if, new_hard_iface);
+       curr_hard_iface = rcu_replace_pointer(bat_priv->primary_if,
+                                             new_hard_iface, 1);
 
        if (!new_hard_iface)
                goto out;
index 3632bd9..d343382 100644 (file)
@@ -71,13 +71,13 @@ static void _batadv_update_route(struct batadv_priv *bat_priv,
         * the code needs to ensure the curr_router variable contains a pointer
         * to the replaced best neighbor.
         */
-       curr_router = rcu_dereference_protected(orig_ifinfo->router, true);
 
        /* increase refcount of new best neighbor */
        if (neigh_node)
                kref_get(&neigh_node->refcount);
 
-       rcu_assign_pointer(orig_ifinfo->router, neigh_node);
+       curr_router = rcu_replace_pointer(orig_ifinfo->router, neigh_node,
+                                         true);
        spin_unlock_bh(&orig_node->neigh_list_lock);
        batadv_orig_ifinfo_put(orig_ifinfo);