From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, saeedm@nvidia.com, horms@kernel.org,
donald.hunter@gmail.com
Subject: [PATCH net-next 4/5] devlink: avoid param type value translations
Date: Fri, 2 May 2025 13:38:20 +0200 [thread overview]
Message-ID: <20250502113821.889-5-jiri@resnulli.us> (raw)
In-Reply-To: <20250502113821.889-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
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>
---
include/net/devlink.h | 10 +++++-----
net/devlink/param.c | 46 ++-----------------------------------------
2 files changed, 7 insertions(+), 49 deletions(-)
diff --git a/include/net/devlink.h b/include/net/devlink.h
index b8783126c1ed..0091f23a40f7 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -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 {
diff --git a/net/devlink/param.c b/net/devlink/param.c
index d0fb7c88bdb8..b29abf8d3ed4 100644
--- a/net/devlink/param.c
+++ b/net/devlink/param.c
@@ -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;
}
--
2.49.0
next prev parent reply other threads:[~2025-05-02 11:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 11:38 [PATCH net-next 0/5] devlink: sanitize variable typed attributes Jiri Pirko
2025-05-02 11:38 ` [PATCH net-next 1/5] tools: ynl-gen: extend block_start/end by noind arg Jiri Pirko
2025-05-03 1:37 ` Jakub Kicinski
2025-05-04 18:25 ` Jiri Pirko
2025-05-02 11:38 ` [PATCH net-next 2/5] tools: ynl-gen: allow noncontiguous enums Jiri Pirko
2025-05-03 1:43 ` Jakub Kicinski
2025-05-04 18:25 ` Jiri Pirko
2025-05-02 11:38 ` [PATCH net-next 3/5] devlink: define enum for attr types of dynamic attributes Jiri Pirko
2025-05-03 1:46 ` Jakub Kicinski
2025-05-04 18:25 ` Jiri Pirko
2025-05-02 11:38 ` Jiri Pirko [this message]
2025-05-02 11:38 ` [PATCH net-next 5/5] devlink: use DEVLINK_VAR_ATTR_TYPE_* instead of NLA_* in fmsg Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250502113821.889-5-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).