Commit 5b9a9ccf authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

net_sched: remove some unnecessary checks in classful schedulers

The class argument to the ->graft(), ->leaf(), ->dump(), ->dump_stats() all
originate from either ->get() or ->walk() and are always valid.

Remove unnecessary checks.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent de6d5cdf
...@@ -1621,11 +1621,9 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1621,11 +1621,9 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
{ {
struct cbq_class *cl = (struct cbq_class*)arg; struct cbq_class *cl = (struct cbq_class*)arg;
if (cl) {
if (new == NULL) { if (new == NULL) {
new = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue, new = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue,
&pfifo_qdisc_ops, &pfifo_qdisc_ops, cl->common.classid);
cl->common.classid);
if (new == NULL) if (new == NULL)
return -ENOBUFS; return -ENOBUFS;
} else { } else {
...@@ -1642,8 +1640,6 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1642,8 +1640,6 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
sch_tree_unlock(sch); sch_tree_unlock(sch);
return 0; return 0;
}
return -ENOENT;
} }
static struct Qdisc * static struct Qdisc *
...@@ -1651,7 +1647,7 @@ cbq_leaf(struct Qdisc *sch, unsigned long arg) ...@@ -1651,7 +1647,7 @@ cbq_leaf(struct Qdisc *sch, unsigned long arg)
{ {
struct cbq_class *cl = (struct cbq_class*)arg; struct cbq_class *cl = (struct cbq_class*)arg;
return cl ? cl->q : NULL; return cl->q;
} }
static void cbq_qlen_notify(struct Qdisc *sch, unsigned long arg) static void cbq_qlen_notify(struct Qdisc *sch, unsigned long arg)
......
...@@ -1203,8 +1203,6 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1203,8 +1203,6 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
{ {
struct hfsc_class *cl = (struct hfsc_class *)arg; struct hfsc_class *cl = (struct hfsc_class *)arg;
if (cl == NULL)
return -ENOENT;
if (cl->level > 0) if (cl->level > 0)
return -EINVAL; return -EINVAL;
if (new == NULL) { if (new == NULL) {
...@@ -1228,7 +1226,7 @@ hfsc_class_leaf(struct Qdisc *sch, unsigned long arg) ...@@ -1228,7 +1226,7 @@ hfsc_class_leaf(struct Qdisc *sch, unsigned long arg)
{ {
struct hfsc_class *cl = (struct hfsc_class *)arg; struct hfsc_class *cl = (struct hfsc_class *)arg;
if (cl != NULL && cl->level == 0) if (cl->level == 0)
return cl->qdisc; return cl->qdisc;
return NULL; return NULL;
......
...@@ -1117,13 +1117,14 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1117,13 +1117,14 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
{ {
struct htb_class *cl = (struct htb_class *)arg; struct htb_class *cl = (struct htb_class *)arg;
if (cl && !cl->level) { if (cl->level)
return -EINVAL;
if (new == NULL && if (new == NULL &&
(new = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue, (new = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue,
&pfifo_qdisc_ops, &pfifo_qdisc_ops,
cl->common.classid)) cl->common.classid)) == NULL)
== NULL)
return -ENOBUFS; return -ENOBUFS;
sch_tree_lock(sch); sch_tree_lock(sch);
*old = cl->un.leaf.q; *old = cl->un.leaf.q;
cl->un.leaf.q = new; cl->un.leaf.q = new;
...@@ -1133,14 +1134,12 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1133,14 +1134,12 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
} }
sch_tree_unlock(sch); sch_tree_unlock(sch);
return 0; return 0;
}
return -ENOENT;
} }
static struct Qdisc *htb_leaf(struct Qdisc *sch, unsigned long arg) static struct Qdisc *htb_leaf(struct Qdisc *sch, unsigned long arg)
{ {
struct htb_class *cl = (struct htb_class *)arg; struct htb_class *cl = (struct htb_class *)arg;
return (cl && !cl->level) ? cl->un.leaf.q : NULL; return !cl->level ? cl->un.leaf.q : NULL;
} }
static void htb_qlen_notify(struct Qdisc *sch, unsigned long arg) static void htb_qlen_notify(struct Qdisc *sch, unsigned long arg)
......
...@@ -298,9 +298,6 @@ static int multiq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -298,9 +298,6 @@ static int multiq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
struct multiq_sched_data *q = qdisc_priv(sch); struct multiq_sched_data *q = qdisc_priv(sch);
unsigned long band = arg - 1; unsigned long band = arg - 1;
if (band >= q->bands)
return -EINVAL;
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
...@@ -320,9 +317,6 @@ multiq_leaf(struct Qdisc *sch, unsigned long arg) ...@@ -320,9 +317,6 @@ multiq_leaf(struct Qdisc *sch, unsigned long arg)
struct multiq_sched_data *q = qdisc_priv(sch); struct multiq_sched_data *q = qdisc_priv(sch);
unsigned long band = arg - 1; unsigned long band = arg - 1;
if (band >= q->bands)
return NULL;
return q->queues[band]; return q->queues[band];
} }
...@@ -353,10 +347,7 @@ static int multiq_dump_class(struct Qdisc *sch, unsigned long cl, ...@@ -353,10 +347,7 @@ static int multiq_dump_class(struct Qdisc *sch, unsigned long cl,
{ {
struct multiq_sched_data *q = qdisc_priv(sch); struct multiq_sched_data *q = qdisc_priv(sch);
if (cl - 1 > q->bands)
return -ENOENT;
tcm->tcm_handle |= TC_H_MIN(cl); tcm->tcm_handle |= TC_H_MIN(cl);
if (q->queues[cl-1])
tcm->tcm_info = q->queues[cl-1]->handle; tcm->tcm_info = q->queues[cl-1]->handle;
return 0; return 0;
} }
......
...@@ -262,9 +262,6 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -262,9 +262,6 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
struct prio_sched_data *q = qdisc_priv(sch); struct prio_sched_data *q = qdisc_priv(sch);
unsigned long band = arg - 1; unsigned long band = arg - 1;
if (band >= q->bands)
return -EINVAL;
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
...@@ -284,9 +281,6 @@ prio_leaf(struct Qdisc *sch, unsigned long arg) ...@@ -284,9 +281,6 @@ prio_leaf(struct Qdisc *sch, unsigned long arg)
struct prio_sched_data *q = qdisc_priv(sch); struct prio_sched_data *q = qdisc_priv(sch);
unsigned long band = arg - 1; unsigned long band = arg - 1;
if (band >= q->bands)
return NULL;
return q->queues[band]; return q->queues[band];
} }
...@@ -316,10 +310,7 @@ static int prio_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff * ...@@ -316,10 +310,7 @@ static int prio_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *
{ {
struct prio_sched_data *q = qdisc_priv(sch); struct prio_sched_data *q = qdisc_priv(sch);
if (cl - 1 > q->bands)
return -ENOENT;
tcm->tcm_handle |= TC_H_MIN(cl); tcm->tcm_handle |= TC_H_MIN(cl);
if (q->queues[cl-1])
tcm->tcm_info = q->queues[cl-1]->handle; tcm->tcm_info = q->queues[cl-1]->handle;
return 0; return 0;
} }
......
...@@ -268,8 +268,6 @@ static int red_dump_class(struct Qdisc *sch, unsigned long cl, ...@@ -268,8 +268,6 @@ static int red_dump_class(struct Qdisc *sch, unsigned long cl,
{ {
struct red_sched_data *q = qdisc_priv(sch); struct red_sched_data *q = qdisc_priv(sch);
if (cl != 1)
return -ENOENT;
tcm->tcm_handle |= TC_H_MIN(1); tcm->tcm_handle |= TC_H_MIN(1);
tcm->tcm_info = q->qdisc->handle; tcm->tcm_info = q->qdisc->handle;
return 0; return 0;
......
...@@ -368,9 +368,6 @@ static int tbf_dump_class(struct Qdisc *sch, unsigned long cl, ...@@ -368,9 +368,6 @@ static int tbf_dump_class(struct Qdisc *sch, unsigned long cl,
{ {
struct tbf_sched_data *q = qdisc_priv(sch); struct tbf_sched_data *q = qdisc_priv(sch);
if (cl != 1) /* only one class */
return -ENOENT;
tcm->tcm_handle |= TC_H_MIN(1); tcm->tcm_handle |= TC_H_MIN(1);
tcm->tcm_info = q->qdisc->handle; tcm->tcm_info = q->qdisc->handle;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment