diff mbox series

[v1,net-next,04/11] net: sched: Use rtnl_register_many().

Message ID 20241011220550.46040-5-kuniyu@amazon.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series rtnetlink: Use rtnl_register_many(). | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 11 this patch: 11
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 86 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Kuniyuki Iwashima Oct. 11, 2024, 10:05 p.m. UTC
We will remove rtnl_register() in favour of rtnl_register_many().

When it succeeds, rtnl_register_many() guarantees all rtnetlink types
in the passed array are supported, and there is no chance that a part
of message types is not supported.

Let's use rtnl_register_many() instead.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
---
 net/sched/act_api.c | 12 +++++++-----
 net/sched/cls_api.c | 24 +++++++++++++-----------
 net/sched/sch_api.c | 18 ++++++++++--------
 3 files changed, 30 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 2714c4ed928e..1caaeef90684 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -2243,13 +2243,15 @@  static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
 	return skb->len;
 }
 
+static const struct rtnl_msg_handler tc_action_rtnl_msg_handlers[] = {
+	{NULL, PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action, 0},
+};
+
 static int __init tc_action_init(void)
 {
-	rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action,
-		      0);
-
+	rtnl_register_many(tc_action_rtnl_msg_handlers);
 	return 0;
 }
 
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 17d97bbe890f..2d9961e6b019 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -4055,6 +4055,18 @@  static struct pernet_operations tcf_net_ops = {
 	.size = sizeof(struct tcf_net),
 };
 
+static const struct rtnl_msg_handler tc_filter_rtnl_msg_handlers[] = {
+	{NULL, PF_UNSPEC, RTM_NEWTFILTER, tc_new_tfilter, NULL,
+	 RTNL_FLAG_DOIT_UNLOCKED},
+	{NULL, PF_UNSPEC, RTM_DELTFILTER, tc_del_tfilter, NULL,
+	 RTNL_FLAG_DOIT_UNLOCKED},
+	{NULL, PF_UNSPEC, RTM_GETTFILTER, tc_get_tfilter, tc_dump_tfilter,
+	 RTNL_FLAG_DOIT_UNLOCKED},
+	{NULL, PF_UNSPEC, RTM_NEWCHAIN, tc_ctl_chain, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_DELCHAIN, tc_ctl_chain, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_GETCHAIN, tc_ctl_chain, tc_dump_chain, 0},
+};
+
 static int __init tc_filter_init(void)
 {
 	int err;
@@ -4068,17 +4080,7 @@  static int __init tc_filter_init(void)
 		goto err_register_pernet_subsys;
 
 	xa_init_flags(&tcf_exts_miss_cookies_xa, XA_FLAGS_ALLOC1);
-
-	rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_new_tfilter, NULL,
-		      RTNL_FLAG_DOIT_UNLOCKED);
-	rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_del_tfilter, NULL,
-		      RTNL_FLAG_DOIT_UNLOCKED);
-	rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_get_tfilter,
-		      tc_dump_tfilter, RTNL_FLAG_DOIT_UNLOCKED);
-	rtnl_register(PF_UNSPEC, RTM_NEWCHAIN, tc_ctl_chain, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_DELCHAIN, tc_ctl_chain, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_GETCHAIN, tc_ctl_chain,
-		      tc_dump_chain, 0);
+	rtnl_register_many(tc_filter_rtnl_msg_handlers);
 
 	return 0;
 
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 2eefa4783879..e475f767bcfb 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -2420,6 +2420,15 @@  static struct pernet_operations psched_net_ops = {
 DEFINE_STATIC_KEY_FALSE(tc_skip_wrapper);
 #endif
 
+static const struct rtnl_msg_handler psched_rtnl_msg_handlers[] = {
+	{NULL, PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc, 0},
+	{NULL, PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL, 0},
+	{NULL, PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass, 0},
+};
+
 static int __init pktsched_init(void)
 {
 	int err;
@@ -2438,14 +2447,7 @@  static int __init pktsched_init(void)
 	register_qdisc(&mq_qdisc_ops);
 	register_qdisc(&noqueue_qdisc_ops);
 
-	rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc,
-		      0);
-	rtnl_register(PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL, 0);
-	rtnl_register(PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass,
-		      0);
+	rtnl_register_many(psched_rtnl_msg_handlers);
 
 	tc_wrapper_init();