Skip to content

Commit aa3fab0

Browse files
committed
Merge branch 'net_sched-redundant-resource-cleanups'
Zhengchao Shao says: ==================== net: sched: remove redundant resource cleanup when init() fails qdisc_create() calls .init() to initialize qdisc. If the initialization fails, qdisc_create() will call .destroy() to release resources. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 40c79ce + d59f4e1 commit aa3fab0

File tree

2 files changed

+17
-44
lines changed

2 files changed

+17
-44
lines changed

net/sched/sch_fq_codel.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -478,26 +478,24 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
478478
if (opt) {
479479
err = fq_codel_change(sch, opt, extack);
480480
if (err)
481-
goto init_failure;
481+
return err;
482482
}
483483

484484
err = tcf_block_get(&q->block, &q->filter_list, sch, extack);
485485
if (err)
486-
goto init_failure;
486+
return err;
487487

488488
if (!q->flows) {
489489
q->flows = kvcalloc(q->flows_cnt,
490490
sizeof(struct fq_codel_flow),
491491
GFP_KERNEL);
492-
if (!q->flows) {
493-
err = -ENOMEM;
494-
goto init_failure;
495-
}
492+
if (!q->flows)
493+
return -ENOMEM;
494+
496495
q->backlogs = kvcalloc(q->flows_cnt, sizeof(u32), GFP_KERNEL);
497-
if (!q->backlogs) {
498-
err = -ENOMEM;
499-
goto alloc_failure;
500-
}
496+
if (!q->backlogs)
497+
return -ENOMEM;
498+
501499
for (i = 0; i < q->flows_cnt; i++) {
502500
struct fq_codel_flow *flow = q->flows + i;
503501

@@ -510,13 +508,6 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
510508
else
511509
sch->flags &= ~TCQ_F_CAN_BYPASS;
512510
return 0;
513-
514-
alloc_failure:
515-
kvfree(q->flows);
516-
q->flows = NULL;
517-
init_failure:
518-
q->flows_cnt = 0;
519-
return err;
520511
}
521512

522513
static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)

net/sched/sch_htb.c

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
11021102

11031103
err = qdisc_class_hash_init(&q->clhash);
11041104
if (err < 0)
1105-
goto err_free_direct_qdiscs;
1105+
return err;
11061106

11071107
if (tb[TCA_HTB_DIRECT_QLEN])
11081108
q->direct_qlen = nla_get_u32(tb[TCA_HTB_DIRECT_QLEN]);
@@ -1123,8 +1123,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
11231123
qdisc = qdisc_create_dflt(dev_queue, &pfifo_qdisc_ops,
11241124
TC_H_MAKE(sch->handle, 0), extack);
11251125
if (!qdisc) {
1126-
err = -ENOMEM;
1127-
goto err_free_qdiscs;
1126+
return -ENOMEM;
11281127
}
11291128

11301129
htb_set_lockdep_class_child(qdisc);
@@ -1142,30 +1141,14 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
11421141
};
11431142
err = htb_offload(dev, &offload_opt);
11441143
if (err)
1145-
goto err_free_qdiscs;
1144+
return err;
11461145

11471146
/* Defer this assignment, so that htb_destroy skips offload-related
11481147
* parts (especially calling ndo_setup_tc) on errors.
11491148
*/
11501149
q->offload = true;
11511150

11521151
return 0;
1153-
1154-
err_free_qdiscs:
1155-
for (ntx = 0; ntx < q->num_direct_qdiscs && q->direct_qdiscs[ntx];
1156-
ntx++)
1157-
qdisc_put(q->direct_qdiscs[ntx]);
1158-
1159-
qdisc_class_hash_destroy(&q->clhash);
1160-
/* Prevent use-after-free and double-free when htb_destroy gets called.
1161-
*/
1162-
q->clhash.hash = NULL;
1163-
q->clhash.hashsize = 0;
1164-
1165-
err_free_direct_qdiscs:
1166-
kfree(q->direct_qdiscs);
1167-
q->direct_qdiscs = NULL;
1168-
return err;
11691152
}
11701153

11711154
static void htb_attach_offload(struct Qdisc *sch)
@@ -1688,13 +1671,12 @@ static void htb_destroy(struct Qdisc *sch)
16881671
qdisc_class_hash_destroy(&q->clhash);
16891672
__qdisc_reset_queue(&q->direct_queue);
16901673

1691-
if (!q->offload)
1692-
return;
1693-
1694-
offload_opt = (struct tc_htb_qopt_offload) {
1695-
.command = TC_HTB_DESTROY,
1696-
};
1697-
htb_offload(dev, &offload_opt);
1674+
if (q->offload) {
1675+
offload_opt = (struct tc_htb_qopt_offload) {
1676+
.command = TC_HTB_DESTROY,
1677+
};
1678+
htb_offload(dev, &offload_opt);
1679+
}
16981680

16991681
if (!q->direct_qdiscs)
17001682
return;

0 commit comments

Comments
 (0)