Subject: Re: [PATCH net-next RFC 1/2] devlink: Add shared descriptor eswitch attr

From: Simon Horman <[email-masked]>
Date: Wed, 28 Feb 2024 13:12:49 +0000

On Wed, Feb 28, 2024 at 03:59:53AM +0200, William Tu wrote:

...

> diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
> index c81cf2dd154f..ac8b0c7105dd 100644
> --- a/net/devlink/netlink_gen.c
> +++ b/net/devlink/netlink_gen.c
> @@ -194,12 +194,14 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA
>  };
>  
>  /* DEVLINK_CMD_ESWITCH_SET - do */
> -static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE + 1] = {
> +static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT + 1] = {
>  	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
>  	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
>  	[DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_MAX(NLA_U16, 1),
>  	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = NLA_POLICY_MAX(NLA_U16, 3),
>  	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
> +	[DEVLINK_ATTR_ESWITCH_SHRDESC_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
> +	[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT] = NLA_POLICY_MAX(NLA_U32, 65535),
>  };

Hi William,

I realise this is probably not central to your purpose in sending an RFC,
but my understanding is that the max value set using NLA_POLICY_MAX
is of type s16, and thus 65535 is too large - it becomes -1.

Flagged by W=1 build with clang-17.

>  
>  /* DEVLINK_CMD_DPIPE_TABLE_GET - do */

...