[PATCH net-next V5 2/6] devlink: Factor out eswitch mode setting
From: Mark Bloch <mbloch@nvidia.com>
Date: 2026-07-07 17:46:00
Also in:
linux-doc, linux-rdma
Subsystem:
devlink, networking [general], the rest · Maintainers:
Jiri Pirko, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
Move the common eswitch mode set checks into a small helper and use it from the netlink eswitch set command. Making the same validation available to the devlink core path that applies eswitch mode defaults. Signed-off-by: Mark Bloch <mbloch@nvidia.com> --- net/devlink/dev.c | 27 ++++++++++++++++++++------- net/devlink/devl_internal.h | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/net/devlink/dev.c b/net/devlink/dev.c
index bcf001554e84..119ef105d0a7 100644
--- a/net/devlink/dev.c
+++ b/net/devlink/dev.c@@ -702,6 +702,25 @@ int devlink_nl_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info) return genlmsg_reply(msg, info); } +int devlink_eswitch_mode_set(struct devlink *devlink, + enum devlink_eswitch_mode mode, + struct netlink_ext_ack *extack) +{ + const struct devlink_ops *ops = devlink->ops; + int err; + + devl_assert_locked(devlink); + + if (!ops->eswitch_mode_set) + return -EOPNOTSUPP; + + err = devlink_rates_check(devlink, devlink_rate_is_node, extack); + if (err) + return err; + + return ops->eswitch_mode_set(devlink, mode, extack); +} + int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = devlink_nl_ctx(info)->devlink;
@@ -712,14 +731,8 @@ int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info) u16 mode; if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE]) { - if (!ops->eswitch_mode_set) - return -EOPNOTSUPP; - err = devlink_rates_check(devlink, devlink_rate_is_node, - info->extack); - if (err) - return err; mode = nla_get_u16(info->attrs[DEVLINK_ATTR_ESWITCH_MODE]); - err = ops->eswitch_mode_set(devlink, mode, info->extack); + err = devlink_eswitch_mode_set(devlink, mode, info->extack); if (err) return err; }
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index cdf894ba5a9d..af43b7163f78 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h@@ -348,6 +348,9 @@ bool devlink_rate_is_node(const struct devlink_rate *devlink_rate); int devlink_rates_check(struct devlink *devlink, bool (*rate_filter)(const struct devlink_rate *), struct netlink_ext_ack *extack); +int devlink_eswitch_mode_set(struct devlink *devlink, + enum devlink_eswitch_mode mode, + struct netlink_ext_ack *extack); /* Linecards */ unsigned int devlink_linecard_index(struct devlink_linecard *linecard);
--
2.43.0