diff mbox series

[net-next,04/15] devlink: move and rename devlink_dpipe_send_and_alloc_skb() helper

Message ID 20230825085321.178134-5-jiri@resnulli.us (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series devlink: finish file split and get retire leftover.c | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
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: 1332 this patch: 1332
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
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: 1355 this patch: 1355
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 117 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiri Pirko Aug. 25, 2023, 8:53 a.m. UTC
From: Jiri Pirko <jiri@nvidia.com>

Since both dpipe and resource code is using this helper, in preparation
for code split to separate files, move
devlink_dpipe_send_and_alloc_skb() helper into netlink.c. Rename it on
the way.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 net/devlink/devl_internal.h |  2 ++
 net/devlink/leftover.c      | 34 +++++++++-------------------------
 net/devlink/netlink.c       | 15 +++++++++++++++
 3 files changed, 26 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index e1a6b7a763b8..66c94957e96c 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -150,6 +150,8 @@  devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
 	return 0;
 }
 
+int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info);
+
 /* Notify */
 void devlink_notify(struct devlink *devlink, enum devlink_command cmd);
 void devlink_ports_notify_register(struct devlink *devlink);
diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c
index 795bfdd41103..1bcd4192099e 100644
--- a/net/devlink/leftover.c
+++ b/net/devlink/leftover.c
@@ -1277,22 +1277,6 @@  static int devlink_dpipe_table_put(struct sk_buff *skb,
 	return -EMSGSIZE;
 }
 
-static int devlink_dpipe_send_and_alloc_skb(struct sk_buff **pskb,
-					    struct genl_info *info)
-{
-	int err;
-
-	if (*pskb) {
-		err = genlmsg_reply(*pskb, info);
-		if (err)
-			return err;
-	}
-	*pskb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
-	if (!*pskb)
-		return -ENOMEM;
-	return 0;
-}
-
 static int devlink_dpipe_tables_fill(struct genl_info *info,
 				     enum devlink_command cmd, int flags,
 				     struct list_head *dpipe_tables,
@@ -1311,7 +1295,7 @@  static int devlink_dpipe_tables_fill(struct genl_info *info,
 	table = list_first_entry(dpipe_tables,
 				 struct devlink_dpipe_table, list);
 start_again:
-	err = devlink_dpipe_send_and_alloc_skb(&skb, info);
+	err = devlink_nl_msg_reply_and_new(&skb, info);
 	if (err)
 		return err;
 
@@ -1358,7 +1342,7 @@  static int devlink_dpipe_tables_fill(struct genl_info *info,
 	nlh = nlmsg_put(skb, info->snd_portid, info->snd_seq,
 			NLMSG_DONE, 0, flags | NLM_F_MULTI);
 	if (!nlh) {
-		err = devlink_dpipe_send_and_alloc_skb(&skb, info);
+		err = devlink_nl_msg_reply_and_new(&skb, info);
 		if (err)
 			return err;
 		goto send_done;
@@ -1551,8 +1535,8 @@  int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
 	struct devlink *devlink;
 	int err;
 
-	err = devlink_dpipe_send_and_alloc_skb(&dump_ctx->skb,
-					       dump_ctx->info);
+	err = devlink_nl_msg_reply_and_new(&dump_ctx->skb,
+					   dump_ctx->info);
 	if (err)
 		return err;
 
@@ -1638,7 +1622,7 @@  static int devlink_dpipe_entries_fill(struct genl_info *info,
 	nlh = nlmsg_put(dump_ctx.skb, info->snd_portid, info->snd_seq,
 			NLMSG_DONE, 0, flags | NLM_F_MULTI);
 	if (!nlh) {
-		err = devlink_dpipe_send_and_alloc_skb(&dump_ctx.skb, info);
+		err = devlink_nl_msg_reply_and_new(&dump_ctx.skb, info);
 		if (err)
 			return err;
 		goto send_done;
@@ -1746,7 +1730,7 @@  static int devlink_dpipe_headers_fill(struct genl_info *info,
 
 	i = 0;
 start_again:
-	err = devlink_dpipe_send_and_alloc_skb(&skb, info);
+	err = devlink_nl_msg_reply_and_new(&skb, info);
 	if (err)
 		return err;
 
@@ -1782,7 +1766,7 @@  static int devlink_dpipe_headers_fill(struct genl_info *info,
 	nlh = nlmsg_put(skb, info->snd_portid, info->snd_seq,
 			NLMSG_DONE, 0, flags | NLM_F_MULTI);
 	if (!nlh) {
-		err = devlink_dpipe_send_and_alloc_skb(&skb, info);
+		err = devlink_nl_msg_reply_and_new(&skb, info);
 		if (err)
 			return err;
 		goto send_done;
@@ -2047,7 +2031,7 @@  static int devlink_resource_fill(struct genl_info *info,
 	resource = list_first_entry(&devlink->resource_list,
 				    struct devlink_resource, list);
 start_again:
-	err = devlink_dpipe_send_and_alloc_skb(&skb, info);
+	err = devlink_nl_msg_reply_and_new(&skb, info);
 	if (err)
 		return err;
 
@@ -2086,7 +2070,7 @@  static int devlink_resource_fill(struct genl_info *info,
 	nlh = nlmsg_put(skb, info->snd_portid, info->snd_seq,
 			NLMSG_DONE, 0, flags | NLM_F_MULTI);
 	if (!nlh) {
-		err = devlink_dpipe_send_and_alloc_skb(&skb, info);
+		err = devlink_nl_msg_reply_and_new(&skb, info);
 		if (err)
 			return err;
 		goto send_done;
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index 72a5005a64cd..5f57afd31dea 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -82,6 +82,21 @@  static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
 	[DEVLINK_ATTR_REGION_DIRECT] = { .type = NLA_FLAG },
 };
 
+int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info)
+{
+	int err;
+
+	if (*msg) {
+		err = genlmsg_reply(*msg, info);
+		if (err)
+			return err;
+	}
+	*msg = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!*msg)
+		return -ENOMEM;
+	return 0;
+}
+
 struct devlink *
 devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs)
 {