Skip to content

Commit c49a944

Browse files
paravmellanoxdavem330
authored andcommitted
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>
1 parent ba356c9 commit c49a944

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎net/core/devlink.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,6 @@ static int devlink_port_type_set(struct devlink *devlink,
811811
int err;
812812

813813
if (devlink->ops->port_type_set) {
814-
if (port_type == DEVLINK_PORT_TYPE_NOTSET)
815-
return -EINVAL;
816814
if (port_type == devlink_port->type)
817815
return 0;
818816
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] = {
70557053
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
70567054
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },
70577055
[DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32 },
7058-
[DEVLINK_ATTR_PORT_TYPE] = { .type = NLA_U16 },
7056+
[DEVLINK_ATTR_PORT_TYPE] = NLA_POLICY_RANGE(NLA_U16, DEVLINK_PORT_TYPE_AUTO,
7057+
DEVLINK_PORT_TYPE_IB),
70597058
[DEVLINK_ATTR_PORT_SPLIT_COUNT] = { .type = NLA_U32 },
70607059
[DEVLINK_ATTR_SB_INDEX] = { .type = NLA_U32 },
70617060
[DEVLINK_ATTR_SB_POOL_INDEX] = { .type = NLA_U16 },

0 commit comments

Comments
 (0)