devlink: move devlink_nl_put_nested_handle() into netlink.c
authorJiri Pirko <jiri@nvidia.com>
Wed, 13 Sep 2023 07:12:36 +0000 (09:12 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 17 Sep 2023 13:01:46 +0000 (14:01 +0100)
As the next patch is going to call this helper out of the linecard.c,
move to netlink.c.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/devlink/devl_internal.h
net/devlink/linecard.c
net/devlink/netlink.c

index 1b05c2c09e27322c0c5a7e4034633d57aee48a07..fbf00de1accfeb93b921ec6dd97f9c7d8885d03f 100644 (file)
@@ -145,6 +145,8 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
        return 0;
 }
 
+int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
+                                struct devlink *devlink);
 int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info);
 
 /* Notify */
index f95abdc93c6621364af5c979f894b76f08efd341..688e89daee6a9e0ee37269d6ebcf90ad7c969370 100644 (file)
@@ -65,32 +65,6 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info)
        return devlink_linecard_get_from_attrs(devlink, info->attrs);
 }
 
-static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
-                                       struct devlink *devlink)
-{
-       struct nlattr *nested_attr;
-
-       nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK);
-       if (!nested_attr)
-               return -EMSGSIZE;
-       if (devlink_nl_put_handle(msg, devlink))
-               goto nla_put_failure;
-       if (!net_eq(net, devlink_net(devlink))) {
-               int id = peernet2id_alloc(net, devlink_net(devlink),
-                                         GFP_KERNEL);
-
-               if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id))
-                       return -EMSGSIZE;
-       }
-
-       nla_nest_end(msg, nested_attr);
-       return 0;
-
-nla_put_failure:
-       nla_nest_cancel(msg, nested_attr);
-       return -EMSGSIZE;
-}
-
 struct devlink_linecard_type {
        const char *type;
        const void *priv;
index fc3e7c029a3befb06d6d825f21888be7e01c969d..48b5cfc2842fa549a5e7b0f420588d44c58aea94 100644 (file)
@@ -82,6 +82,32 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_REGION_DIRECT] = { .type = NLA_FLAG },
 };
 
+int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
+                                struct devlink *devlink)
+{
+       struct nlattr *nested_attr;
+
+       nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK);
+       if (!nested_attr)
+               return -EMSGSIZE;
+       if (devlink_nl_put_handle(msg, devlink))
+               goto nla_put_failure;
+       if (!net_eq(net, devlink_net(devlink))) {
+               int id = peernet2id_alloc(net, devlink_net(devlink),
+                                         GFP_KERNEL);
+
+               if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id))
+                       return -EMSGSIZE;
+       }
+
+       nla_nest_end(msg, nested_attr);
+       return 0;
+
+nla_put_failure:
+       nla_nest_cancel(msg, nested_attr);
+       return -EMSGSIZE;
+}
+
 int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info)
 {
        int err;