]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
devlink: avoid param type value translations
authorJiri Pirko <jiri@nvidia.com>
Mon, 5 May 2025 11:45:12 +0000 (13:45 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 7 May 2025 01:21:11 +0000 (18:21 -0700)
Assign DEVLINK_PARAM_TYPE_* enum values to DEVLINK_VAR_ATTR_TYPE_* to
ensure the same values are used internally and in UAPI. Benefit from
that by removing the value translations.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Link: https://patch.msgid.link/20250505114513.53370-4-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/devlink.h
net/devlink/param.c

index b8783126c1ed2848f837d9118ab5ff6bbec9139a..0091f23a40f7d951ec3d1e2f7c176d1ebf3e0379 100644 (file)
@@ -420,11 +420,11 @@ typedef u64 devlink_resource_occ_get_t(void *priv);
 
 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
 enum devlink_param_type {
-       DEVLINK_PARAM_TYPE_U8,
-       DEVLINK_PARAM_TYPE_U16,
-       DEVLINK_PARAM_TYPE_U32,
-       DEVLINK_PARAM_TYPE_STRING,
-       DEVLINK_PARAM_TYPE_BOOL,
+       DEVLINK_PARAM_TYPE_U8 = DEVLINK_VAR_ATTR_TYPE_U8,
+       DEVLINK_PARAM_TYPE_U16 = DEVLINK_VAR_ATTR_TYPE_U16,
+       DEVLINK_PARAM_TYPE_U32 = DEVLINK_VAR_ATTR_TYPE_U32,
+       DEVLINK_PARAM_TYPE_STRING = DEVLINK_VAR_ATTR_TYPE_STRING,
+       DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG,
 };
 
 union devlink_param_value {
index d0fb7c88bdb818bee8b89fc84b5df028a1be36fe..b29abf8d3ed4a006c57855f310c6aef41cf7f03d 100644 (file)
@@ -166,25 +166,6 @@ static int devlink_param_set(struct devlink *devlink,
        return param->set(devlink, param->id, ctx, extack);
 }
 
-static int
-devlink_param_type_to_var_attr_type(enum devlink_param_type param_type)
-{
-       switch (param_type) {
-       case DEVLINK_PARAM_TYPE_U8:
-               return DEVLINK_VAR_ATTR_TYPE_U8;
-       case DEVLINK_PARAM_TYPE_U16:
-               return DEVLINK_VAR_ATTR_TYPE_U16;
-       case DEVLINK_PARAM_TYPE_U32:
-               return DEVLINK_VAR_ATTR_TYPE_U32;
-       case DEVLINK_PARAM_TYPE_STRING:
-               return DEVLINK_VAR_ATTR_TYPE_STRING;
-       case DEVLINK_PARAM_TYPE_BOOL:
-               return DEVLINK_VAR_ATTR_TYPE_FLAG;
-       default:
-               return -EINVAL;
-       }
-}
-
 static int
 devlink_nl_param_value_fill_one(struct sk_buff *msg,
                                enum devlink_param_type type,
@@ -247,7 +228,6 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
        struct devlink_param_gset_ctx ctx;
        struct nlattr *param_values_list;
        struct nlattr *param_attr;
-       int var_attr_type;
        void *hdr;
        int err;
        int i;
@@ -293,11 +273,7 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
                goto param_nest_cancel;
        if (param->generic && nla_put_flag(msg, DEVLINK_ATTR_PARAM_GENERIC))
                goto param_nest_cancel;
-
-       var_attr_type = devlink_param_type_to_var_attr_type(param->type);
-       if (var_attr_type < 0)
-               goto param_nest_cancel;
-       if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, var_attr_type))
+       if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, param->type))
                goto param_nest_cancel;
 
        param_values_list = nla_nest_start_noflag(msg,
@@ -419,25 +395,7 @@ devlink_param_type_get_from_info(struct genl_info *info,
        if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PARAM_TYPE))
                return -EINVAL;
 
-       switch (nla_get_u8(info->attrs[DEVLINK_ATTR_PARAM_TYPE])) {
-       case DEVLINK_VAR_ATTR_TYPE_U8:
-               *param_type = DEVLINK_PARAM_TYPE_U8;
-               break;
-       case DEVLINK_VAR_ATTR_TYPE_U16:
-               *param_type = DEVLINK_PARAM_TYPE_U16;
-               break;
-       case DEVLINK_VAR_ATTR_TYPE_U32:
-               *param_type = DEVLINK_PARAM_TYPE_U32;
-               break;
-       case DEVLINK_VAR_ATTR_TYPE_STRING:
-               *param_type = DEVLINK_PARAM_TYPE_STRING;
-               break;
-       case DEVLINK_VAR_ATTR_TYPE_FLAG:
-               *param_type = DEVLINK_PARAM_TYPE_BOOL;
-               break;
-       default:
-               return -EINVAL;
-       }
+       *param_type = nla_get_u8(info->attrs[DEVLINK_ATTR_PARAM_TYPE]);
 
        return 0;
 }