Skip to content

Commit d59f4e1

Browse files
zhengchaoshaodavem330
authored andcommitted
net: sched: htb: remove redundant resource cleanup in htb_init()
If htb_init() fails, qdisc_create() invokes htb_destroy() to clear resources. Therefore, remove redundant resource cleanup in htb_init(). Signed-off-by: Zhengchao Shao <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 494f506 commit d59f4e1

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

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)