net: rtnl: use rcu_replace_pointer_rtnl in rtnl_unregister_*
authorPedro Tammela <pctammela@mojatatu.com>
Fri, 15 Dec 2023 17:57:11 +0000 (14:57 -0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 18 Dec 2023 02:05:45 +0000 (02:05 +0000)
With the introduction of the rcu_replace_pointer_rtnl helper,
cleanup the rtnl_unregister_* functions to use the helper instead
of open coding it.

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/rtnetlink.c

index 5e0ab4c08f72ed857adb0fce1bdf9b086394c268..94c4572512b819cf2a7197ec1ecea0864a5aa555 100644 (file)
@@ -342,8 +342,7 @@ int rtnl_unregister(int protocol, int msgtype)
                return -ENOENT;
        }
 
-       link = rtnl_dereference(tab[msgindex]);
-       RCU_INIT_POINTER(tab[msgindex], NULL);
+       link = rcu_replace_pointer_rtnl(tab[msgindex], NULL);
        rtnl_unlock();
 
        kfree_rcu(link, rcu);
@@ -368,18 +367,13 @@ void rtnl_unregister_all(int protocol)
        BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
 
        rtnl_lock();
-       tab = rtnl_dereference(rtnl_msg_handlers[protocol]);
+       tab = rcu_replace_pointer_rtnl(rtnl_msg_handlers[protocol], NULL);
        if (!tab) {
                rtnl_unlock();
                return;
        }
-       RCU_INIT_POINTER(rtnl_msg_handlers[protocol], NULL);
        for (msgindex = 0; msgindex < RTM_NR_MSGTYPES; msgindex++) {
-               link = rtnl_dereference(tab[msgindex]);
-               if (!link)
-                       continue;
-
-               RCU_INIT_POINTER(tab[msgindex], NULL);
+               link = rcu_replace_pointer_rtnl(tab[msgindex], NULL);
                kfree_rcu(link, rcu);
        }
        rtnl_unlock();