[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <AM9PR04MB83977621774954ABED31037896D39@AM9PR04MB8397.eurprd04.prod.outlook.com>
Date: Mon, 30 Jan 2023 18:37:02 +0000
From: Claudiu Manoil <claudiu.manoil@....com>
To: Vladimir Oltean <vladimir.oltean@....com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
CC: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Vinicius Costa Gomes <vinicius.gomes@...el.com>,
Kurt Kanzenbach <kurt@...utronix.de>,
Jacob Keller <jacob.e.keller@...el.com>,
Jamal Hadi Salim <jhs@...atatu.com>,
Cong Wang <xiyou.wangcong@...il.com>,
Jiri Pirko <jiri@...nulli.us>
Subject: RE: [PATCH v4 net-next 08/15] net/sched: mqprio: allow offloading
drivers to request queue count validation
> -----Original Message-----
> From: Vladimir Oltean <vladimir.oltean@....com>
> Sent: Monday, January 30, 2023 7:32 PM
[...]
> Subject: [PATCH v4 net-next 08/15] net/sched: mqprio: allow offloading drivers
> to request queue count validation
>
[...]
> +static int mqprio_validate_queue_counts(struct net_device *dev,
> + const struct tc_mqprio_qopt *qopt)
> +{
> + int i, j;
> +
> + for (i = 0; i < qopt->num_tc; i++) {
> + unsigned int last = qopt->offset[i] + qopt->count[i];
> +
> + /* Verify the queue count is in tx range being equal to the
> + * real_num_tx_queues indicates the last queue is in use.
> + */
> + if (qopt->offset[i] >= dev->real_num_tx_queues ||
> + !qopt->count[i] ||
> + last > dev->real_num_tx_queues)
> + return -EINVAL;
> +
> + /* Verify that the offset and counts do not overlap */
> + for (j = i + 1; j < qopt->num_tc; j++) {
> + if (last > qopt->offset[j])
> + return -EINVAL;
> + }
> + }
> +
> + return 0;
> +}
> +
Not related to this series, but the above O(n^2) code snippet....
If last[i] := offset[i] + count[i] and last[i] <= offset[i+1],
then offset[i] + count[i] <= offset[i+1] for every i := 0, num_tc - 1.
In other words, it's enough to check that last[i] <= offset[i+1] to make
sure there's no interval overlap, and it's O(n).
Powered by blists - more mailing lists