@@ -17,7 +17,7 @@ void rtnl_register(int protocol, int msgtype,
rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
int rtnl_register_module(struct module *owner, int protocol, int msgtype,
rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
-int rtnl_unregister(int protocol, int msgtype);
+void rtnl_unregister(int protocol, int msgtype);
void rtnl_unregister_all(int protocol);
static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
@@ -281,10 +281,8 @@ void rtnl_register(int protocol, int msgtype,
* rtnl_unregister - Unregister a rtnetlink message type
* @protocol: Protocol family or PF_UNSPEC
* @msgtype: rtnetlink message type
- *
- * Returns 0 on success or a negative error code.
*/
-int rtnl_unregister(int protocol, int msgtype)
+void rtnl_unregister(int protocol, int msgtype)
{
struct rtnl_link __rcu **tab;
struct rtnl_link *link;
@@ -295,18 +293,18 @@ int rtnl_unregister(int protocol, int msgtype)
rtnl_lock();
tab = rtnl_dereference(rtnl_msg_handlers[protocol]);
- if (!tab) {
- rtnl_unlock();
- return -ENOENT;
- }
+ if (!tab)
+ goto unlock;
link = rtnl_dereference(tab[msgindex]);
- rcu_assign_pointer(tab[msgindex], NULL);
- rtnl_unlock();
+ if (!link)
+ goto unlock;
+ rcu_assign_pointer(tab[msgindex], NULL);
kfree_rcu(link, rcu);
- return 0;
+unlock:
+ rtnl_unlock();
}
EXPORT_SYMBOL_GPL(rtnl_unregister);
The value 'link' may be NULL in rtnl_unregister(), this leads to kfree_rcu(NULL, xxx), so add this case handling. And modify the return value to 'void' in rtnl_unregister(). there is no case using it. Fixes: addf9b90de22 (net: rtnetlink: use rcu to free rtnl message handlers) Fixes: 51e13685bd93 (rtnetlink: RCU-annotate both dimensions of rtnl_msg_handlers) Signed-off-by: Yajun Deng <yajun.deng@linux.dev> --- include/net/rtnetlink.h | 2 +- net/core/rtnetlink.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-)