From: Shay Drory <shayd@nvidia.com>
To: <netdev@vger.kernel.org>, <kuba@kernel.org>, <davem@davemloft.net>
Cc: <danielj@nvidia.com>, <yishaih@nvidia.com>, <jiri@nvidia.com>,
<saeedm@nvidia.com>, <parav@nvidia.com>
Subject: [PATCH net-next 2/8] devlink: Validate port function request
Date: Wed, 30 Nov 2022 13:52:11 +0200 [thread overview]
Message-ID: <20221130115217.7171-3-shayd@nvidia.com> (raw)
In-Reply-To: <20221130115217.7171-1-shayd@nvidia.com>
In order to avoid partial request processing, validate the request
before processing it.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
net/core/devlink.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/net/core/devlink.c b/net/core/devlink.c
index cea154ddce7a..485348697290 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -1644,11 +1644,6 @@ static int devlink_port_function_hw_addr_set(struct devlink_port *port,
}
}
- if (!ops->port_function_hw_addr_set) {
- NL_SET_ERR_MSG_MOD(extack, "Port doesn't support function attributes");
- return -EOPNOTSUPP;
- }
-
return ops->port_function_hw_addr_set(port, hw_addr, hw_addr_len,
extack);
}
@@ -1662,12 +1657,26 @@ static int devlink_port_fn_state_set(struct devlink_port *port,
state = nla_get_u8(attr);
ops = port->devlink->ops;
- if (!ops->port_fn_state_set) {
+ return ops->port_fn_state_set(port, state, extack);
+}
+
+static int devlink_port_function_validate(struct devlink_port *devlink_port,
+ struct nlattr **tb,
+ struct netlink_ext_ack *extack)
+{
+ const struct devlink_ops *ops = devlink_port->devlink->ops;
+
+ if (tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] &&
+ !ops->port_function_hw_addr_set) {
+ NL_SET_ERR_MSG_MOD(extack, "Port doesn't support function attributes");
+ return -EOPNOTSUPP;
+ }
+ if (tb[DEVLINK_PORT_FN_ATTR_STATE] && !ops->port_fn_state_set) {
NL_SET_ERR_MSG_MOD(extack,
"Function does not support state setting");
return -EOPNOTSUPP;
}
- return ops->port_fn_state_set(port, state, extack);
+ return 0;
}
static int devlink_port_function_set(struct devlink_port *port,
@@ -1684,6 +1693,10 @@ static int devlink_port_function_set(struct devlink_port *port,
return err;
}
+ err = devlink_port_function_validate(port, tb, extack);
+ if (err)
+ return err;
+
attr = tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR];
if (attr) {
err = devlink_port_function_hw_addr_set(port, attr, extack);
--
2.38.1
next prev parent reply other threads:[~2022-11-30 11:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-30 11:52 [PATCH net-next 0/8] devlink: Add port function attribute to enable/disable Roce and migratable Shay Drory
2022-11-30 11:52 ` [PATCH net-next 1/8] net/mlx5: Introduce IFC bits for migratable Shay Drory
2022-11-30 11:52 ` Shay Drory [this message]
2022-11-30 11:52 ` [PATCH net-next 3/8] devlink: Move devlink port function hw_addr attr documentation Shay Drory
2022-11-30 11:52 ` [PATCH net-next 4/8] devlink: Expose port function commands to control RoCE Shay Drory
2022-11-30 11:52 ` [PATCH net-next 5/8] net/mlx5: Add generic getters for other functions caps Shay Drory
2022-11-30 11:52 ` [PATCH net-next 6/8] net/mlx5: E-Switch, Implement devlink port function cmds to control RoCE Shay Drory
2022-11-30 11:52 ` [PATCH net-next 7/8] devlink: Expose port function commands to control migratable Shay Drory
2022-12-01 8:46 ` kernel test robot
2022-11-30 11:52 ` [PATCH net-next 8/8] net/mlx5: E-Switch, Implement devlink port function cmds " Shay Drory
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=20221130115217.7171-3-shayd@nvidia.com \
--to=shayd@nvidia.com \
--cc=danielj@nvidia.com \
--cc=davem@davemloft.net \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=parav@nvidia.com \
--cc=saeedm@nvidia.com \
--cc=yishaih@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).