hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/sched/sch_cbs.c
....@@ -1,13 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * net/sched/sch_cbs.c Credit Based Shaper
34 *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version
7
- * 2 of the License, or (at your option) any later version.
8
- *
95 * Authors: Vinicius Costa Gomes <vinicius.gomes@intel.com>
10
- *
116 */
127
138 /* Credit Based Shaper (CBS)
....@@ -93,13 +88,14 @@
9388 struct Qdisc *child,
9489 struct sk_buff **to_free)
9590 {
91
+ unsigned int len = qdisc_pkt_len(skb);
9692 int err;
9793
9894 err = child->ops->enqueue(skb, child, to_free);
9995 if (err != NET_XMIT_SUCCESS)
10096 return err;
10197
102
- qdisc_qstats_backlog_inc(sch, skb);
98
+ sch->qstats.backlog += len;
10399 sch->q.qlen++;
104100
105101 return NET_XMIT_SUCCESS;
....@@ -313,7 +309,7 @@
313309 {
314310 struct ethtool_link_ksettings ecmd;
315311 int speed = SPEED_10;
316
- int port_rate = -1;
312
+ int port_rate;
317313 int err;
318314
319315 err = __ethtool_get_link_ksettings(dev, &ecmd);
....@@ -370,7 +366,8 @@
370366 struct tc_cbs_qopt *qopt;
371367 int err;
372368
373
- err = nla_parse_nested(tb, TCA_CBS_MAX, opt, cbs_policy, extack);
369
+ err = nla_parse_nested_deprecated(tb, TCA_CBS_MAX, opt, cbs_policy,
370
+ extack);
374371 if (err < 0)
375372 return err;
376373
....@@ -405,7 +402,6 @@
405402 {
406403 struct cbs_sched_data *q = qdisc_priv(sch);
407404 struct net_device *dev = qdisc_dev(sch);
408
- int err;
409405
410406 if (!opt) {
411407 NL_SET_ERR_MSG(extack, "Missing CBS qdisc options which are mandatory");
....@@ -417,6 +413,10 @@
417413 if (!q->qdisc)
418414 return -ENOMEM;
419415
416
+ spin_lock(&cbs_list_lock);
417
+ list_add(&q->cbs_list, &cbs_list);
418
+ spin_unlock(&cbs_list_lock);
419
+
420420 qdisc_hash_add(q->qdisc, false);
421421
422422 q->queue = sch->dev_queue - netdev_get_tx_queue(dev, 0);
....@@ -426,17 +426,7 @@
426426
427427 qdisc_watchdog_init(&q->watchdog, sch);
428428
429
- err = cbs_change(sch, opt, extack);
430
- if (err)
431
- return err;
432
-
433
- if (!q->offload) {
434
- spin_lock(&cbs_list_lock);
435
- list_add(&q->cbs_list, &cbs_list);
436
- spin_unlock(&cbs_list_lock);
437
- }
438
-
439
- return 0;
429
+ return cbs_change(sch, opt, extack);
440430 }
441431
442432 static void cbs_destroy(struct Qdisc *sch)
....@@ -444,15 +434,18 @@
444434 struct cbs_sched_data *q = qdisc_priv(sch);
445435 struct net_device *dev = qdisc_dev(sch);
446436
447
- spin_lock(&cbs_list_lock);
448
- list_del(&q->cbs_list);
449
- spin_unlock(&cbs_list_lock);
437
+ /* Nothing to do if we couldn't create the underlying qdisc */
438
+ if (!q->qdisc)
439
+ return;
450440
451441 qdisc_watchdog_cancel(&q->watchdog);
452442 cbs_disable_offload(dev, q);
453443
454
- if (q->qdisc)
455
- qdisc_put(q->qdisc);
444
+ spin_lock(&cbs_list_lock);
445
+ list_del(&q->cbs_list);
446
+ spin_unlock(&cbs_list_lock);
447
+
448
+ qdisc_put(q->qdisc);
456449 }
457450
458451 static int cbs_dump(struct Qdisc *sch, struct sk_buff *skb)
....@@ -461,7 +454,7 @@
461454 struct tc_cbs_qopt opt = { };
462455 struct nlattr *nest;
463456
464
- nest = nla_nest_start(skb, TCA_OPTIONS);
457
+ nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
465458 if (!nest)
466459 goto nla_put_failure;
467460