Subject: Re: [PATCH net-next v2 3/4] net/sched: sch_qfq: refactor parsing of netlink parameters

From: Simon Horman <[email-masked]>
Date: Wed, 19 Apr 2023 14:53:50 +0200

On Mon, Apr 17, 2023 at 02:12:17PM -0300, Pedro Tammela wrote:
> Two parameters can be transformed into netlink policies and
> validated while parsing the netlink message.
> 
> Acked-by: Jamal Hadi Salim <[email-masked]>
> Signed-off-by: Pedro Tammela <[email-masked]>

Reviewed-by: Simon Horman <[email-masked]>

> ---
>  net/sched/sch_qfq.c | 28 +++++++++++++---------------
>  1 file changed, 13 insertions(+), 15 deletions(-)
> 
> diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
> index 323609cfbc67..151102ac8cce 100644
> --- a/net/sched/sch_qfq.c
> +++ b/net/sched/sch_qfq.c
> @@ -214,9 +214,15 @@ static struct qfq_class *qfq_find_class(struct Qdisc *sch, u32 classid)
>  	return container_of(clc, struct qfq_class, common);
>  }
>  
> +static struct netlink_range_validation lmax_range = {
> +	.min = QFQ_MIN_LMAX,
> +	.max = (1UL << QFQ_MTU_SHIFT),
> +};
> +
>  static const struct nla_policy qfq_policy[TCA_QFQ_MAX + 1] = {
> -	[TCA_QFQ_WEIGHT] = { .type = NLA_U32 },
> -	[TCA_QFQ_LMAX] = { .type = NLA_U32 },
> +	[TCA_QFQ_WEIGHT] =
> +		NLA_POLICY_RANGE(NLA_U32, 1, (1UL << QFQ_MAX_WSHIFT)),
> +	[TCA_QFQ_LMAX] = NLA_POLICY_FULL_RANGE(NLA_U32, &lmax_range),
>  };

Maybe someday we can teach this file about the BIT macro.

...