o net/sched: some trivial code cleanups, making some code smaller

Smaller by not calling write_unlock two times.
parent aee01ebf
...@@ -65,37 +65,38 @@ struct tcf_proto_ops * tcf_proto_lookup_ops(struct rtattr *kind) ...@@ -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) int register_tcf_proto_ops(struct tcf_proto_ops *ops)
{ {
struct tcf_proto_ops *t, **tp; struct tcf_proto_ops *t, **tp;
int rc = -EEXIST;
write_lock(&cls_mod_lock); write_lock(&cls_mod_lock);
for (tp = &tcf_proto_base; (t=*tp) != NULL; tp = &t->next) { for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next)
if (strcmp(ops->kind, t->kind) == 0) { if (!strcmp(ops->kind, t->kind))
write_unlock(&cls_mod_lock); goto out;
return -EEXIST;
}
}
ops->next = NULL; ops->next = NULL;
*tp = ops; *tp = ops;
rc = 0;
out:
write_unlock(&cls_mod_lock); write_unlock(&cls_mod_lock);
return 0; return rc;
} }
int unregister_tcf_proto_ops(struct tcf_proto_ops *ops) int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
{ {
struct tcf_proto_ops *t, **tp; struct tcf_proto_ops *t, **tp;
int rc = -ENOENT;
write_lock(&cls_mod_lock); write_lock(&cls_mod_lock);
for (tp = &tcf_proto_base; (t=*tp) != NULL; tp = &t->next) for (tp = &tcf_proto_base; (t=*tp) != NULL; tp = &t->next)
if (t == ops) if (t == ops)
break; break;
if (!t) { if (!t)
write_unlock(&cls_mod_lock); goto out;
return -ENOENT;
}
*tp = t->next; *tp = t->next;
rc = 0;
out:
write_unlock(&cls_mod_lock); write_unlock(&cls_mod_lock);
return 0; return rc;
} }
static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n, 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) ...@@ -371,11 +372,8 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
q = dev->qdisc_sleeping; q = dev->qdisc_sleeping;
else else
q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent)); q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent));
if (q == NULL) { if (!q)
read_unlock(&qdisc_tree_lock); goto out;
dev_put(dev);
return skb->len;
}
if ((cops = q->ops->cl_ops) == NULL) if ((cops = q->ops->cl_ops) == NULL)
goto errout; goto errout;
if (TC_H_MIN(tcm->tcm_parent)) { if (TC_H_MIN(tcm->tcm_parent)) {
...@@ -425,7 +423,7 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -425,7 +423,7 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
errout: errout:
if (cl) if (cl)
cops->put(q, cl); cops->put(q, cl);
out:
read_unlock(&qdisc_tree_lock); read_unlock(&qdisc_tree_lock);
dev_put(dev); dev_put(dev);
return skb->len; return skb->len;
......
...@@ -152,7 +152,7 @@ static int fw_delete(struct tcf_proto *tp, unsigned long arg) ...@@ -152,7 +152,7 @@ static int fw_delete(struct tcf_proto *tp, unsigned long arg)
struct fw_filter **fp; struct fw_filter **fp;
if (head == NULL || f == NULL) if (head == NULL || f == NULL)
return -EINVAL; goto out;
for (fp=&head->ht[fw_hash(f->id)]; *fp; fp = &(*fp)->next) { for (fp=&head->ht[fw_hash(f->id)]; *fp; fp = &(*fp)->next) {
if (*fp == f) { if (*fp == f) {
...@@ -171,6 +171,7 @@ static int fw_delete(struct tcf_proto *tp, unsigned long arg) ...@@ -171,6 +171,7 @@ static int fw_delete(struct tcf_proto *tp, unsigned long arg)
return 0; return 0;
} }
} }
out:
return -EINVAL; return -EINVAL;
} }
......
...@@ -203,17 +203,17 @@ static __inline__ struct tc_u_knode * ...@@ -203,17 +203,17 @@ static __inline__ struct tc_u_knode *
u32_lookup_key(struct tc_u_hnode *ht, u32 handle) u32_lookup_key(struct tc_u_hnode *ht, u32 handle)
{ {
unsigned sel; unsigned sel;
struct tc_u_knode *n; struct tc_u_knode *n = NULL;
sel = TC_U32_HASH(handle); sel = TC_U32_HASH(handle);
if (sel > ht->divisor) if (sel > ht->divisor)
return 0; goto out;
for (n = ht->ht[sel]; n; n = n->next) for (n = ht->ht[sel]; n; n = n->next)
if (n->handle == handle) if (n->handle == handle)
return n; break;
out:
return NULL; return n;
} }
......
...@@ -139,21 +139,19 @@ static rwlock_t qdisc_mod_lock = RW_LOCK_UNLOCKED; ...@@ -139,21 +139,19 @@ static rwlock_t qdisc_mod_lock = RW_LOCK_UNLOCKED;
/* The list of all installed queueing disciplines. */ /* The list of all installed queueing disciplines. */
static struct Qdisc_ops *qdisc_base = NULL; static struct Qdisc_ops *qdisc_base;
/* Register/uregister queueing discipline */ /* Register/uregister queueing discipline */
int register_qdisc(struct Qdisc_ops *qops) int register_qdisc(struct Qdisc_ops *qops)
{ {
struct Qdisc_ops *q, **qp; struct Qdisc_ops *q, **qp;
int rc = -EEXIST;
write_lock(&qdisc_mod_lock); write_lock(&qdisc_mod_lock);
for (qp = &qdisc_base; (q=*qp)!=NULL; qp = &q->next) { for (qp = &qdisc_base; (q = *qp) != NULL; qp = &q->next)
if (strcmp(qops->id, q->id) == 0) { if (!strcmp(qops->id, q->id))
write_unlock(&qdisc_mod_lock); goto out;
return -EEXIST;
}
}
if (qops->enqueue == NULL) if (qops->enqueue == NULL)
qops->enqueue = noop_qdisc_ops.enqueue; qops->enqueue = noop_qdisc_ops.enqueue;
...@@ -164,8 +162,10 @@ int register_qdisc(struct Qdisc_ops *qops) ...@@ -164,8 +162,10 @@ int register_qdisc(struct Qdisc_ops *qops)
qops->next = NULL; qops->next = NULL;
*qp = qops; *qp = qops;
rc = 0;
out:
write_unlock(&qdisc_mod_lock); write_unlock(&qdisc_mod_lock);
return 0; return rc;
} }
int unregister_qdisc(struct Qdisc_ops *qops) int unregister_qdisc(struct Qdisc_ops *qops)
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
/* Thanks to Doron Oz for this hack /* Thanks to Doron Oz for this hack
*/ */
static int nf_registered = 0; static int nf_registered;
struct ingress_qdisc_data { struct ingress_qdisc_data {
struct Qdisc *q; struct Qdisc *q;
...@@ -237,15 +237,13 @@ used on the egress (might slow things for an iota) ...@@ -237,15 +237,13 @@ used on the egress (might slow things for an iota)
} }
/* after ipt_filter */ /* after ipt_filter */
static struct nf_hook_ops ing_ops = static struct nf_hook_ops ing_ops = {
{ .hook = ing_hook,
{ NULL, NULL}, .owner = THIS_MODULE,
ing_hook, .pf = PF_INET,
THIS_MODULE, .hooknum = NF_IP_PRE_ROUTING,
PF_INET, .priority = NF_IP_PRI_FILTER + 1,
NF_IP_PRE_ROUTING, }
NF_IP_PRI_FILTER + 1
};
int ingress_init(struct Qdisc *sch,struct rtattr *opt) int ingress_init(struct Qdisc *sch,struct rtattr *opt)
{ {
...@@ -255,7 +253,7 @@ 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) { if (nf_register_hook(&ing_ops) < 0) {
printk("ingress qdisc registration error \n"); printk("ingress qdisc registration error \n");
goto error; goto error;
} }
nf_registered++; nf_registered++;
} }
......
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