Skip to content

Commit 71bcb09

Browse files
Stephen Hemmingerdavem330
authored andcommitted
tc: check for errors in gen_rate_estimator creation
The functions gen_new_estimator and gen_replace_estimator can return errors, but they were being ignored. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0e991ec commit 71bcb09

6 files changed

Lines changed: 97 additions & 41 deletions

File tree

‎net/sched/act_police.c‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,21 @@ static int tcf_act_police_locate(struct nlattr *nla, struct nlattr *est,
185185
if (parm->peakrate.rate) {
186186
P_tab = qdisc_get_rtab(&parm->peakrate,
187187
tb[TCA_POLICE_PEAKRATE]);
188-
if (P_tab == NULL) {
189-
qdisc_put_rtab(R_tab);
188+
if (P_tab == NULL)
190189
goto failure;
191-
}
192190
}
193191
}
194-
/* No failure allowed after this point */
192+
195193
spin_lock_bh(&police->tcf_lock);
194+
if (est) {
195+
err = gen_replace_estimator(&police->tcf_bstats,
196+
&police->tcf_rate_est,
197+
&police->tcf_lock, est);
198+
if (err)
199+
goto failure_unlock;
200+
}
201+
202+
/* No failure allowed after this point */
196203
if (R_tab != NULL) {
197204
qdisc_put_rtab(police->tcfp_R_tab);
198205
police->tcfp_R_tab = R_tab;
@@ -217,10 +224,6 @@ static int tcf_act_police_locate(struct nlattr *nla, struct nlattr *est,
217224

218225
if (tb[TCA_POLICE_AVRATE])
219226
police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]);
220-
if (est)
221-
gen_replace_estimator(&police->tcf_bstats,
222-
&police->tcf_rate_est,
223-
&police->tcf_lock, est);
224227

225228
spin_unlock_bh(&police->tcf_lock);
226229
if (ret != ACT_P_CREATED)
@@ -238,7 +241,13 @@ static int tcf_act_police_locate(struct nlattr *nla, struct nlattr *est,
238241
a->priv = police;
239242
return ret;
240243

244+
failure_unlock:
245+
spin_unlock_bh(&police->tcf_lock);
241246
failure:
247+
if (P_tab)
248+
qdisc_put_rtab(P_tab);
249+
if (R_tab)
250+
qdisc_put_rtab(R_tab);
242251
if (ret == ACT_P_CREATED)
243252
kfree(police);
244253
return err;

‎net/sched/sch_api.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,12 @@ static int qdisc_change(struct Qdisc *sch, struct nlattr **tca)
880880
sch->stab = stab;
881881

882882
if (tca[TCA_RATE])
883+
/* NB: ignores errors from replace_estimator
884+
because change can't be undone. */
883885
gen_replace_estimator(&sch->bstats, &sch->rate_est,
884-
qdisc_root_sleeping_lock(sch),
885-
tca[TCA_RATE]);
886+
qdisc_root_sleeping_lock(sch),
887+
tca[TCA_RATE]);
888+
886889
return 0;
887890
}
888891

‎net/sched/sch_cbq.c‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,11 +1765,23 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
17651765
}
17661766

17671767
if (tb[TCA_CBQ_RATE]) {
1768-
rtab = qdisc_get_rtab(nla_data(tb[TCA_CBQ_RATE]), tb[TCA_CBQ_RTAB]);
1768+
rtab = qdisc_get_rtab(nla_data(tb[TCA_CBQ_RATE]),
1769+
tb[TCA_CBQ_RTAB]);
17691770
if (rtab == NULL)
17701771
return -EINVAL;
17711772
}
17721773

1774+
if (tca[TCA_RATE]) {
1775+
err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
1776+
qdisc_root_sleeping_lock(sch),
1777+
tca[TCA_RATE]);
1778+
if (err) {
1779+
if (rtab)
1780+
qdisc_put_rtab(rtab);
1781+
return err;
1782+
}
1783+
}
1784+
17731785
/* Change class parameters */
17741786
sch_tree_lock(sch);
17751787

@@ -1805,10 +1817,6 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
18051817

18061818
sch_tree_unlock(sch);
18071819

1808-
if (tca[TCA_RATE])
1809-
gen_replace_estimator(&cl->bstats, &cl->rate_est,
1810-
qdisc_root_sleeping_lock(sch),
1811-
tca[TCA_RATE]);
18121820
return 0;
18131821
}
18141822

@@ -1855,6 +1863,17 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
18551863
cl = kzalloc(sizeof(*cl), GFP_KERNEL);
18561864
if (cl == NULL)
18571865
goto failure;
1866+
1867+
if (tca[TCA_RATE]) {
1868+
err = gen_new_estimator(&cl->bstats, &cl->rate_est,
1869+
qdisc_root_sleeping_lock(sch),
1870+
tca[TCA_RATE]);
1871+
if (err) {
1872+
kfree(cl);
1873+
goto failure;
1874+
}
1875+
}
1876+
18581877
cl->R_tab = rtab;
18591878
rtab = NULL;
18601879
cl->refcnt = 1;
@@ -1896,10 +1915,6 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
18961915

18971916
qdisc_class_hash_grow(sch, &q->clhash);
18981917

1899-
if (tca[TCA_RATE])
1900-
gen_new_estimator(&cl->bstats, &cl->rate_est,
1901-
qdisc_root_sleeping_lock(sch), tca[TCA_RATE]);
1902-
19031918
*arg = (unsigned long)cl;
19041919
return 0;
19051920

‎net/sched/sch_drr.c‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,19 @@ static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
8282
quantum = psched_mtu(qdisc_dev(sch));
8383

8484
if (cl != NULL) {
85+
if (tca[TCA_RATE]) {
86+
err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
87+
qdisc_root_sleeping_lock(sch),
88+
tca[TCA_RATE]);
89+
if (err)
90+
return err;
91+
}
92+
8593
sch_tree_lock(sch);
8694
if (tb[TCA_DRR_QUANTUM])
8795
cl->quantum = quantum;
8896
sch_tree_unlock(sch);
8997

90-
if (tca[TCA_RATE])
91-
gen_replace_estimator(&cl->bstats, &cl->rate_est,
92-
qdisc_root_sleeping_lock(sch),
93-
tca[TCA_RATE]);
9498
return 0;
9599
}
96100

@@ -106,10 +110,16 @@ static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
106110
if (cl->qdisc == NULL)
107111
cl->qdisc = &noop_qdisc;
108112

109-
if (tca[TCA_RATE])
110-
gen_replace_estimator(&cl->bstats, &cl->rate_est,
111-
qdisc_root_sleeping_lock(sch),
112-
tca[TCA_RATE]);
113+
if (tca[TCA_RATE]) {
114+
err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
115+
qdisc_root_sleeping_lock(sch),
116+
tca[TCA_RATE]);
117+
if (err) {
118+
qdisc_destroy(cl->qdisc);
119+
kfree(cl);
120+
return err;
121+
}
122+
}
113123

114124
sch_tree_lock(sch);
115125
qdisc_class_hash_insert(&q->clhash, &cl->common);

‎net/sched/sch_hfsc.c‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,14 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
10181018
}
10191019
cur_time = psched_get_time();
10201020

1021+
if (tca[TCA_RATE]) {
1022+
err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
1023+
qdisc_root_sleeping_lock(sch),
1024+
tca[TCA_RATE]);
1025+
if (err)
1026+
return err;
1027+
}
1028+
10211029
sch_tree_lock(sch);
10221030
if (rsc != NULL)
10231031
hfsc_change_rsc(cl, rsc, cur_time);
@@ -1034,10 +1042,6 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
10341042
}
10351043
sch_tree_unlock(sch);
10361044

1037-
if (tca[TCA_RATE])
1038-
gen_replace_estimator(&cl->bstats, &cl->rate_est,
1039-
qdisc_root_sleeping_lock(sch),
1040-
tca[TCA_RATE]);
10411045
return 0;
10421046
}
10431047

@@ -1063,6 +1067,16 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
10631067
if (cl == NULL)
10641068
return -ENOBUFS;
10651069

1070+
if (tca[TCA_RATE]) {
1071+
err = gen_new_estimator(&cl->bstats, &cl->rate_est,
1072+
qdisc_root_sleeping_lock(sch),
1073+
tca[TCA_RATE]);
1074+
if (err) {
1075+
kfree(cl);
1076+
return err;
1077+
}
1078+
}
1079+
10661080
if (rsc != NULL)
10671081
hfsc_change_rsc(cl, rsc, 0);
10681082
if (fsc != NULL)
@@ -1093,9 +1107,6 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
10931107

10941108
qdisc_class_hash_grow(sch, &q->clhash);
10951109

1096-
if (tca[TCA_RATE])
1097-
gen_new_estimator(&cl->bstats, &cl->rate_est,
1098-
qdisc_root_sleeping_lock(sch), tca[TCA_RATE]);
10991110
*arg = (unsigned long)cl;
11001111
return 0;
11011112
}

‎net/sched/sch_htb.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,14 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
13321332
if ((cl = kzalloc(sizeof(*cl), GFP_KERNEL)) == NULL)
13331333
goto failure;
13341334

1335-
gen_new_estimator(&cl->bstats, &cl->rate_est,
1336-
qdisc_root_sleeping_lock(sch),
1337-
tca[TCA_RATE] ? : &est.nla);
1335+
err = gen_new_estimator(&cl->bstats, &cl->rate_est,
1336+
qdisc_root_sleeping_lock(sch),
1337+
tca[TCA_RATE] ? : &est.nla);
1338+
if (err) {
1339+
kfree(cl);
1340+
goto failure;
1341+
}
1342+
13381343
cl->refcnt = 1;
13391344
cl->children = 0;
13401345
INIT_LIST_HEAD(&cl->un.leaf.drop_list);
@@ -1386,10 +1391,13 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
13861391
if (parent)
13871392
parent->children++;
13881393
} else {
1389-
if (tca[TCA_RATE])
1390-
gen_replace_estimator(&cl->bstats, &cl->rate_est,
1391-
qdisc_root_sleeping_lock(sch),
1392-
tca[TCA_RATE]);
1394+
if (tca[TCA_RATE]) {
1395+
err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
1396+
qdisc_root_sleeping_lock(sch),
1397+
tca[TCA_RATE]);
1398+
if (err)
1399+
return err;
1400+
}
13931401
sch_tree_lock(sch);
13941402
}
13951403

0 commit comments

Comments
 (0)