devlink: Enhance policy to validate eswitch mode value
authorParav Pandit <parav@nvidia.com>
Mon, 21 Sep 2020 16:41:29 +0000 (19:41 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 23 Sep 2020 00:38:42 +0000 (17:38 -0700)
Use range checking facility of nla_policy to validate eswitch mode input
attribute 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>
net/core/devlink.c

index 045468390480bdc3b4d897331c58dd971669fa2a..b0b3af3ef3556d847fc17cbc759fc4e2279e764f 100644 (file)
@@ -7064,7 +7064,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE] = { .type = NLA_U8 },
        [DEVLINK_ATTR_SB_THRESHOLD] = { .type = NLA_U32 },
        [DEVLINK_ATTR_SB_TC_INDEX] = { .type = NLA_U16 },
-       [DEVLINK_ATTR_ESWITCH_MODE] = { .type = NLA_U16 },
+       [DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_RANGE(NLA_U16, DEVLINK_ESWITCH_MODE_LEGACY,
+                                                      DEVLINK_ESWITCH_MODE_SWITCHDEV),
        [DEVLINK_ATTR_ESWITCH_INLINE_MODE] = { .type = NLA_U8 },
        [DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = { .type = NLA_U8 },
        [DEVLINK_ATTR_DPIPE_TABLE_NAME] = { .type = NLA_NUL_STRING },