On 9/17/20 11:20 AM, Parav Pandit wrote:
> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index d152489e48da..c82098cb75da 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -595,6 +598,40 @@ devlink_port_function_hw_addr_fill(struct devlink 
> *devlink, const struct devlink
>       return 0;
>  }
>  
> +static bool devlink_port_function_state_valid(u8 state)

you have a named enum so why not 'enum devlink_port_function_state state'?


> +{
> +     return state == DEVLINK_PORT_FUNCTION_STATE_INACTIVE ||
> +            state == DEVLINK_PORT_FUNCTION_STATE_ACTIVE;
> +}
> +
> +static int devlink_port_function_state_fill(struct devlink *devlink, const 
> struct devlink_ops *ops,
> +                                         struct devlink_port *port, struct 
> sk_buff *msg,
> +                                         struct netlink_ext_ack *extack, 
> bool *msg_updated)
> +{
> +     enum devlink_port_function_state state;
> +     int err;
> +
> +     if (!ops->port_function_state_get)
> +             return 0;
> +
> +     err = ops->port_function_state_get(devlink, port, &state, extack);
> +     if (err) {
> +             if (err == -EOPNOTSUPP)
> +                     return 0;
> +             return err;
> +     }
> +     if (!devlink_port_function_state_valid(state)) {
> +             WARN_ON(1);

WARN_ON_ONCE at most.

> +             NL_SET_ERR_MSG_MOD(extack, "Invalid state value read from 
> driver");
> +             return -EINVAL;
> +     }
> +     err = nla_put_u8(msg, DEVLINK_PORT_FUNCTION_ATTR_STATE, state);
> +     if (err)
> +             return err;
> +     *msg_updated = true;
> +     return 0;
> +}
> +
>  static int
>  devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port 
> *port,
>                                  struct netlink_ext_ack *extack)

Reply via email to