1 From 1ffba0c4d1122688268e59832a5e2bbc0917cac7 Mon Sep 17 00:00:00 2001
2 From: Camelia Groza <camelia.groza@nxp.com>
3 Date: Wed, 3 Oct 2018 16:37:06 +0300
4 Subject: [PATCH] sdk_dpaa: ceetm: avoid double frees on error paths
6 The stack calls the destroy() callback when a qdisc init() fails.
7 We stop calling it ourselves and trust the stack do the cleanup.
9 Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
11 .../ethernet/freescale/sdk_dpaa/dpaa_eth_ceetm.c | 94 ++++++++--------------
12 1 file changed, 34 insertions(+), 60 deletions(-)
14 --- a/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_ceetm.c
15 +++ b/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_ceetm.c
16 @@ -687,16 +687,13 @@ static int ceetm_init_root(struct Qdisc
19 if (sch->parent != TC_H_ROOT) {
20 - pr_err("CEETM: a root ceetm qdisc can not be attached to a class\n");
21 - tcf_block_put(priv->block);
22 - qdisc_class_hash_destroy(&priv->clhash);
23 + pr_err("CEETM: a root ceetm qdisc must be root\n");
28 pr_err("CEETM: the interface is lacking a mac\n");
34 /* Pre-allocate underlying pfifo qdiscs.
35 @@ -713,8 +710,7 @@ static int ceetm_init_root(struct Qdisc
36 sizeof(priv->root.qdiscs[0]),
38 if (!priv->root.qdiscs) {
44 for (i = 0; i < dev->num_tx_queues; i++) {
45 @@ -724,10 +720,8 @@ static int ceetm_init_root(struct Qdisc
47 qdisc = qdisc_create_dflt(dev_queue, &pfifo_qdisc_ops,
56 priv->root.qdiscs[i] = qdisc;
57 qdisc->flags |= TCQ_F_ONETXQUEUE;
58 @@ -739,8 +733,7 @@ static int ceetm_init_root(struct Qdisc
59 if (!priv->root.qstats) {
60 pr_err(KBUILD_BASENAME " : %s : alloc_percpu() failed\n",
67 priv->shaped = qopt->shaped;
68 @@ -754,7 +747,7 @@ static int ceetm_init_root(struct Qdisc
70 pr_err(KBUILD_BASENAME " : %s : failed to claim the SP\n",
77 @@ -766,7 +759,7 @@ static int ceetm_init_root(struct Qdisc
79 pr_err(KBUILD_BASENAME " : %s : failed to claim the LNI\n",
86 @@ -775,7 +768,7 @@ static int ceetm_init_root(struct Qdisc
88 pr_err(KBUILD_BASENAME " : %s : failed to link the SP and LNI\n",
95 @@ -786,7 +779,7 @@ static int ceetm_init_root(struct Qdisc
97 pr_err(KBUILD_BASENAME " : %s : failed to configure the LNI shaper\n",
103 bps = priv->root.rate << 3; /* Bps -> bps */
104 @@ -794,7 +787,7 @@ static int ceetm_init_root(struct Qdisc
106 pr_err(KBUILD_BASENAME " : %s : failed to configure the LNI shaper\n",
108 - goto err_init_root;
112 bps = priv->root.ceil << 3; /* Bps -> bps */
113 @@ -802,7 +795,7 @@ static int ceetm_init_root(struct Qdisc
115 pr_err(KBUILD_BASENAME " : %s : failed to configure the LNI shaper\n",
117 - goto err_init_root;
122 @@ -810,10 +803,6 @@ static int ceetm_init_root(struct Qdisc
124 dpa_enable_ceetm(dev);
128 - ceetm_destroy(sch);
132 /* Configure a prio ceetm qdisc */
133 @@ -830,15 +819,13 @@ static int ceetm_init_prio(struct Qdisc
135 if (sch->parent == TC_H_ROOT) {
136 pr_err("CEETM: a prio ceetm qdisc can not be root\n");
138 - goto err_init_prio;
142 parent_qdisc = qdisc_lookup(dev, TC_H_MAJ(sch->parent));
143 if (strcmp(parent_qdisc->ops->id, ceetm_qdisc_ops.id)) {
144 pr_err("CEETM: a ceetm qdisc can not be attached to other qdisc/class types\n");
146 - goto err_init_prio;
150 /* Obtain the parent root ceetm_class */
151 @@ -846,8 +833,7 @@ static int ceetm_init_prio(struct Qdisc
153 if (!parent_cl || parent_cl->type != CEETM_ROOT) {
154 pr_err("CEETM: a prio ceetm qdiscs can be added only under a root ceetm class\n");
156 - goto err_init_prio;
160 priv->prio.parent = parent_cl;
161 @@ -863,8 +849,7 @@ static int ceetm_init_prio(struct Qdisc
163 pr_err(KBUILD_BASENAME " : %s : kzalloc() failed\n",
166 - goto err_init_prio;
170 child_cl->prio.cstats = alloc_percpu(struct ceetm_class_stats);
171 @@ -907,8 +892,7 @@ static int ceetm_init_prio(struct Qdisc
174 ceetm_cls_destroy(sch, child_cl);
176 - ceetm_destroy(sch);
177 + /* Note: ceetm_destroy() will be called by our caller */
181 @@ -928,16 +912,14 @@ static int ceetm_init_wbfs(struct Qdisc
182 /* Validate inputs */
183 if (sch->parent == TC_H_ROOT) {
184 pr_err("CEETM: a wbfs ceetm qdiscs can not be root\n");
186 - goto err_init_wbfs;
190 /* Obtain the parent prio ceetm qdisc */
191 parent_qdisc = qdisc_lookup(dev, TC_H_MAJ(sch->parent));
192 if (strcmp(parent_qdisc->ops->id, ceetm_qdisc_ops.id)) {
193 pr_err("CEETM: a ceetm qdisc can not be attached to other qdisc/class types\n");
195 - goto err_init_wbfs;
199 /* Obtain the parent prio ceetm class */
200 @@ -946,28 +928,24 @@ static int ceetm_init_wbfs(struct Qdisc
202 if (!parent_cl || parent_cl->type != CEETM_PRIO) {
203 pr_err("CEETM: a wbfs ceetm qdiscs can be added only under a prio ceetm class\n");
205 - goto err_init_wbfs;
209 if (!qopt->qcount || !qopt->qweight[0]) {
210 pr_err("CEETM: qcount and qweight are mandatory for a wbfs ceetm qdisc\n");
212 - goto err_init_wbfs;
216 priv->shaped = parent_cl->shaped;
218 if (!priv->shaped && (qopt->cr || qopt->er)) {
219 pr_err("CEETM: CR/ER can be enabled only for shaped wbfs ceetm qdiscs\n");
221 - goto err_init_wbfs;
225 if (priv->shaped && !(qopt->cr || qopt->er)) {
226 pr_err("CEETM: either CR or ER must be enabled for shaped wbfs ceetm qdiscs\n");
228 - goto err_init_wbfs;
232 /* Obtain the parent root ceetm class */
233 @@ -975,16 +953,14 @@ static int ceetm_init_wbfs(struct Qdisc
234 if ((root_cl->root.wbfs_grp_a && root_cl->root.wbfs_grp_b) ||
235 root_cl->root.wbfs_grp_large) {
236 pr_err("CEETM: no more wbfs classes are available\n");
238 - goto err_init_wbfs;
242 if ((root_cl->root.wbfs_grp_a || root_cl->root.wbfs_grp_b) &&
243 qopt->qcount == CEETM_MAX_WBFS_QCOUNT) {
244 pr_err("CEETM: only %d wbfs classes are available\n",
245 CEETM_MIN_WBFS_QCOUNT);
247 - goto err_init_wbfs;
251 priv->wbfs.parent = parent_cl;
252 @@ -1013,7 +989,7 @@ static int ceetm_init_wbfs(struct Qdisc
254 pr_err(KBUILD_BASENAME " : %s : failed to get group details\n",
256 - goto err_init_wbfs;
261 @@ -1031,7 +1007,7 @@ static int ceetm_init_wbfs(struct Qdisc
263 pr_err(KBUILD_BASENAME " : %s : failed to get group details\n",
265 - goto err_init_wbfs;
270 @@ -1044,7 +1020,7 @@ static int ceetm_init_wbfs(struct Qdisc
271 err = qman_ceetm_channel_set_group(priv->wbfs.ch, small_group, prio_a,
274 - goto err_init_wbfs;
278 err = qman_ceetm_channel_set_group_cr_eligibility(priv->wbfs.ch,
279 @@ -1053,7 +1029,7 @@ static int ceetm_init_wbfs(struct Qdisc
281 pr_err(KBUILD_BASENAME " : %s : failed to set group CR eligibility\n",
283 - goto err_init_wbfs;
287 err = qman_ceetm_channel_set_group_er_eligibility(priv->wbfs.ch,
288 @@ -1062,7 +1038,7 @@ static int ceetm_init_wbfs(struct Qdisc
290 pr_err(KBUILD_BASENAME " : %s : failed to set group ER eligibility\n",
292 - goto err_init_wbfs;
297 @@ -1072,8 +1048,7 @@ static int ceetm_init_wbfs(struct Qdisc
299 pr_err(KBUILD_BASENAME " : %s : kzalloc() failed\n",
302 - goto err_init_wbfs;
306 child_cl->wbfs.cstats = alloc_percpu(struct ceetm_class_stats);
307 @@ -1130,8 +1105,7 @@ static int ceetm_init_wbfs(struct Qdisc
310 ceetm_cls_destroy(sch, child_cl);
312 - ceetm_destroy(sch);
313 + /* Note: ceetm_destroy() will be called by our caller */
317 @@ -1202,7 +1176,7 @@ static int ceetm_init(struct Qdisc *sch,
320 pr_err(KBUILD_BASENAME " : %s : invalid qdisc\n", __func__);
321 - ceetm_destroy(sch);
322 + /* Note: ceetm_destroy() will be called by our caller */
326 @@ -1549,7 +1523,7 @@ static int ceetm_cls_change(struct Qdisc
329 if (!cl && priv->type != CEETM_ROOT) {
330 - pr_err("CEETM: only root ceetm classes can be attached to the root ceetm qdisc\n");
331 + pr_err("CEETM: root ceetm classes can be attached to the root ceetm qdisc only\n");