Skip to content

Commit ce84380

Browse files
committed
devlink: avoid param type value translations
JIRA: https://issues.redhat.com/browse/RHEL-104975 commit f9e7893 Author: Jiri Pirko <jiri@resnulli.us> Date: Mon May 5 13:45:12 2025 +0200 devlink: avoid param type value translations 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> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent fd00d5b commit ce84380

File tree

2 files changed

+7
-49
lines changed

2 files changed

+7
-49
lines changed

include/net/devlink.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ typedef u64 devlink_resource_occ_get_t(void *priv);
420420

421421
#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
422422
enum devlink_param_type {
423-
DEVLINK_PARAM_TYPE_U8,
424-
DEVLINK_PARAM_TYPE_U16,
425-
DEVLINK_PARAM_TYPE_U32,
426-
DEVLINK_PARAM_TYPE_STRING,
427-
DEVLINK_PARAM_TYPE_BOOL,
423+
DEVLINK_PARAM_TYPE_U8 = DEVLINK_VAR_ATTR_TYPE_U8,
424+
DEVLINK_PARAM_TYPE_U16 = DEVLINK_VAR_ATTR_TYPE_U16,
425+
DEVLINK_PARAM_TYPE_U32 = DEVLINK_VAR_ATTR_TYPE_U32,
426+
DEVLINK_PARAM_TYPE_STRING = DEVLINK_VAR_ATTR_TYPE_STRING,
427+
DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG,
428428
};
429429

430430
union devlink_param_value {

net/devlink/param.c

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,6 @@ static int devlink_param_set(struct devlink *devlink,
166166
return param->set(devlink, param->id, ctx, extack);
167167
}
168168

169-
static int
170-
devlink_param_type_to_var_attr_type(enum devlink_param_type param_type)
171-
{
172-
switch (param_type) {
173-
case DEVLINK_PARAM_TYPE_U8:
174-
return DEVLINK_VAR_ATTR_TYPE_U8;
175-
case DEVLINK_PARAM_TYPE_U16:
176-
return DEVLINK_VAR_ATTR_TYPE_U16;
177-
case DEVLINK_PARAM_TYPE_U32:
178-
return DEVLINK_VAR_ATTR_TYPE_U32;
179-
case DEVLINK_PARAM_TYPE_STRING:
180-
return DEVLINK_VAR_ATTR_TYPE_STRING;
181-
case DEVLINK_PARAM_TYPE_BOOL:
182-
return DEVLINK_VAR_ATTR_TYPE_FLAG;
183-
default:
184-
return -EINVAL;
185-
}
186-
}
187-
188169
static int
189170
devlink_nl_param_value_fill_one(struct sk_buff *msg,
190171
enum devlink_param_type type,
@@ -247,7 +228,6 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
247228
struct devlink_param_gset_ctx ctx;
248229
struct nlattr *param_values_list;
249230
struct nlattr *param_attr;
250-
int var_attr_type;
251231
void *hdr;
252232
int err;
253233
int i;
@@ -293,11 +273,7 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
293273
goto param_nest_cancel;
294274
if (param->generic && nla_put_flag(msg, DEVLINK_ATTR_PARAM_GENERIC))
295275
goto param_nest_cancel;
296-
297-
var_attr_type = devlink_param_type_to_var_attr_type(param->type);
298-
if (var_attr_type < 0)
299-
goto param_nest_cancel;
300-
if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, var_attr_type))
276+
if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, param->type))
301277
goto param_nest_cancel;
302278

303279
param_values_list = nla_nest_start_noflag(msg,
@@ -419,25 +395,7 @@ devlink_param_type_get_from_info(struct genl_info *info,
419395
if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PARAM_TYPE))
420396
return -EINVAL;
421397

422-
switch (nla_get_u8(info->attrs[DEVLINK_ATTR_PARAM_TYPE])) {
423-
case DEVLINK_VAR_ATTR_TYPE_U8:
424-
*param_type = DEVLINK_PARAM_TYPE_U8;
425-
break;
426-
case DEVLINK_VAR_ATTR_TYPE_U16:
427-
*param_type = DEVLINK_PARAM_TYPE_U16;
428-
break;
429-
case DEVLINK_VAR_ATTR_TYPE_U32:
430-
*param_type = DEVLINK_PARAM_TYPE_U32;
431-
break;
432-
case DEVLINK_VAR_ATTR_TYPE_STRING:
433-
*param_type = DEVLINK_PARAM_TYPE_STRING;
434-
break;
435-
case DEVLINK_VAR_ATTR_TYPE_FLAG:
436-
*param_type = DEVLINK_PARAM_TYPE_BOOL;
437-
break;
438-
default:
439-
return -EINVAL;
440-
}
398+
*param_type = nla_get_u8(info->attrs[DEVLINK_ATTR_PARAM_TYPE]);
441399

442400
return 0;
443401
}

0 commit comments

Comments
 (0)