diff options
author | Parav Pandit <parav@nvidia.com> | 2020-09-21 19:41:30 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2020-09-22 17:38:42 -0700 |
commit | c49a94405b39d3e3293da98f621fe4243f3cc4fa (patch) | |
tree | db5d37005b047942476b2ae9b9741965877ae5f7 /net/core/devlink.c | |
parent | ba356c90985defec30c8680077bf571a50a4004b (diff) | |
download | lwn-c49a94405b39d3e3293da98f621fe4243f3cc4fa.tar.gz lwn-c49a94405b39d3e3293da98f621fe4243f3cc4fa.zip |
devlink: Enhance policy to validate port type input value
Use range checking facility of nla_policy to validate port type
attribute input value is valid or not.
Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/devlink.c')
-rw-r--r-- | net/core/devlink.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c index b0b3af3ef355..ac32b672a04b 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -811,8 +811,6 @@ static int devlink_port_type_set(struct devlink *devlink, int err; if (devlink->ops->port_type_set) { - if (port_type == DEVLINK_PORT_TYPE_NOTSET) - return -EINVAL; if (port_type == devlink_port->type) return 0; err = devlink->ops->port_type_set(devlink_port, port_type); @@ -7055,7 +7053,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING }, [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING }, [DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32 }, - [DEVLINK_ATTR_PORT_TYPE] = { .type = NLA_U16 }, + [DEVLINK_ATTR_PORT_TYPE] = NLA_POLICY_RANGE(NLA_U16, DEVLINK_PORT_TYPE_AUTO, + DEVLINK_PORT_TYPE_IB), [DEVLINK_ATTR_PORT_SPLIT_COUNT] = { .type = NLA_U32 }, [DEVLINK_ATTR_SB_INDEX] = { .type = NLA_U32 }, [DEVLINK_ATTR_SB_POOL_INDEX] = { .type = NLA_U16 }, |