diff options
| author | Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 2003-04-29 20:49:19 -0300 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 2003-04-29 20:49:19 -0300 |
| commit | a814cf52f28d9def564d82f9813db970336f60fd (patch) | |
| tree | 9c6ff3095d30261f3cd1747bb26f22f97816de9f | |
| parent | aee01ebf76e73261039aeb0cbd4238d4bc6a449c (diff) | |
o net/sched: some trivial code cleanups, making some code smaller
Smaller by not calling write_unlock two times.
| -rw-r--r-- | net/sched/cls_api.c | 34 | ||||
| -rw-r--r-- | net/sched/cls_fw.c | 3 | ||||
| -rw-r--r-- | net/sched/cls_u32.c | 10 | ||||
| -rw-r--r-- | net/sched/sch_api.c | 16 | ||||
| -rw-r--r-- | net/sched/sch_ingress.c | 20 |
5 files changed, 40 insertions, 43 deletions
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index a578156cab91..0958503dcca7 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -65,37 +65,38 @@ struct tcf_proto_ops * tcf_proto_lookup_ops(struct rtattr *kind) int register_tcf_proto_ops(struct tcf_proto_ops *ops) { struct tcf_proto_ops *t, **tp; + int rc = -EEXIST; write_lock(&cls_mod_lock); - for (tp = &tcf_proto_base; (t=*tp) != NULL; tp = &t->next) { - if (strcmp(ops->kind, t->kind) == 0) { - write_unlock(&cls_mod_lock); - return -EEXIST; - } - } + for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next) + if (!strcmp(ops->kind, t->kind)) + goto out; ops->next = NULL; *tp = ops; + rc = 0; +out: write_unlock(&cls_mod_lock); - return 0; + return rc; } int unregister_tcf_proto_ops(struct tcf_proto_ops *ops) { struct tcf_proto_ops *t, **tp; + int rc = -ENOENT; write_lock(&cls_mod_lock); for (tp = &tcf_proto_base; (t=*tp) != NULL; tp = &t->next) if (t == ops) break; - if (!t) { - write_unlock(&cls_mod_lock); - return -ENOENT; - } + if (!t) + goto out; *tp = t->next; + rc = 0; +out: write_unlock(&cls_mod_lock); - return 0; + return rc; } static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n, @@ -371,11 +372,8 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) q = dev->qdisc_sleeping; else q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent)); - if (q == NULL) { - read_unlock(&qdisc_tree_lock); - dev_put(dev); - return skb->len; - } + if (!q) + goto out; if ((cops = q->ops->cl_ops) == NULL) goto errout; if (TC_H_MIN(tcm->tcm_parent)) { @@ -425,7 +423,7 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) errout: if (cl) cops->put(q, cl); - +out: read_unlock(&qdisc_tree_lock); dev_put(dev); return skb->len; diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index a3053c225806..caca242d22a6 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c @@ -152,7 +152,7 @@ static int fw_delete(struct tcf_proto *tp, unsigned long arg) struct fw_filter **fp; if (head == NULL || f == NULL) - return -EINVAL; + goto out; for (fp=&head->ht[fw_hash(f->id)]; *fp; fp = &(*fp)->next) { if (*fp == f) { @@ -171,6 +171,7 @@ static int fw_delete(struct tcf_proto *tp, unsigned long arg) return 0; } } +out: return -EINVAL; } diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index cf9f3fefa526..96488808098a 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -203,17 +203,17 @@ static __inline__ struct tc_u_knode * u32_lookup_key(struct tc_u_hnode *ht, u32 handle) { unsigned sel; - struct tc_u_knode *n; + struct tc_u_knode *n = NULL; sel = TC_U32_HASH(handle); if (sel > ht->divisor) - return 0; + goto out; for (n = ht->ht[sel]; n; n = n->next) if (n->handle == handle) - return n; - - return NULL; + break; +out: + return n; } diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 857a2d824222..30c3586ce0b0 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -139,21 +139,19 @@ static rwlock_t qdisc_mod_lock = RW_LOCK_UNLOCKED; /* The list of all installed queueing disciplines. */ -static struct Qdisc_ops *qdisc_base = NULL; +static struct Qdisc_ops *qdisc_base; /* Register/uregister queueing discipline */ int register_qdisc(struct Qdisc_ops *qops) { struct Qdisc_ops *q, **qp; + int rc = -EEXIST; write_lock(&qdisc_mod_lock); - for (qp = &qdisc_base; (q=*qp)!=NULL; qp = &q->next) { - if (strcmp(qops->id, q->id) == 0) { - write_unlock(&qdisc_mod_lock); - return -EEXIST; - } - } + for (qp = &qdisc_base; (q = *qp) != NULL; qp = &q->next) + if (!strcmp(qops->id, q->id)) + goto out; if (qops->enqueue == NULL) qops->enqueue = noop_qdisc_ops.enqueue; @@ -164,8 +162,10 @@ int register_qdisc(struct Qdisc_ops *qops) qops->next = NULL; *qp = qops; + rc = 0; +out: write_unlock(&qdisc_mod_lock); - return 0; + return rc; } int unregister_qdisc(struct Qdisc_ops *qops) diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c index 48a63bae0124..b37e5c7f54f8 100644 --- a/net/sched/sch_ingress.c +++ b/net/sched/sch_ingress.c @@ -45,7 +45,7 @@ /* Thanks to Doron Oz for this hack */ -static int nf_registered = 0; +static int nf_registered; struct ingress_qdisc_data { struct Qdisc *q; @@ -237,15 +237,13 @@ used on the egress (might slow things for an iota) } /* after ipt_filter */ -static struct nf_hook_ops ing_ops = -{ - { NULL, NULL}, - ing_hook, - THIS_MODULE, - PF_INET, - NF_IP_PRE_ROUTING, - NF_IP_PRI_FILTER + 1 -}; +static struct nf_hook_ops ing_ops = { + .hook = ing_hook, + .owner = THIS_MODULE, + .pf = PF_INET, + .hooknum = NF_IP_PRE_ROUTING, + .priority = NF_IP_PRI_FILTER + 1, +} int ingress_init(struct Qdisc *sch,struct rtattr *opt) { @@ -255,7 +253,7 @@ int ingress_init(struct Qdisc *sch,struct rtattr *opt) if (nf_register_hook(&ing_ops) < 0) { printk("ingress qdisc registration error \n"); goto error; - } + } nf_registered++; } |
