From: Eric Dumazet Date: Fri, 20 Dec 2013 18:04:18 +0000 (-0800) Subject: net_sched: fix a regression in tcf_proto_lookup_ops() X-Git-Url: http://pileus.org/git/?a=commitdiff_plain;h=dcd76081340da2f262a8c8efade200cc7554a3b9;hp=568a153a22d8f338a5ebda70e6bd139f6d8bb2c3;p=~andy%2Flinux net_sched: fix a regression in tcf_proto_lookup_ops() list_for_each_entry(t, &tcf_proto_base, head) doesn't exit with t = NULL if we reached the end of the list. Signed-off-by: Eric Dumazet Fixes: 3627287463b4 ("net_sched: convert tcf_proto_ops to use struct list_head") Cc: Cong Wang Reviewed-by: Cong Wang Signed-off-by: David S. Miller --- diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 6b085cf27a6..12e882ef596 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -40,20 +40,20 @@ static DEFINE_RWLOCK(cls_mod_lock); static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind) { - const struct tcf_proto_ops *t = NULL; + const struct tcf_proto_ops *t, *res = NULL; if (kind) { read_lock(&cls_mod_lock); list_for_each_entry(t, &tcf_proto_base, head) { if (nla_strcmp(kind, t->kind) == 0) { - if (!try_module_get(t->owner)) - t = NULL; + if (try_module_get(t->owner)) + res = t; break; } } read_unlock(&cls_mod_lock); } - return t; + return res; } /* Register(unregister) new classifier type */ @@ -82,15 +82,13 @@ int unregister_tcf_proto_ops(struct tcf_proto_ops *ops) int rc = -ENOENT; write_lock(&cls_mod_lock); - list_for_each_entry(t, &tcf_proto_base, head) - if (t == ops) + list_for_each_entry(t, &tcf_proto_base, head) { + if (t == ops) { + list_del(&t->head); + rc = 0; break; - - if (!t) - goto out; - list_del(&t->head); - rc = 0; -out: + } + } write_unlock(&cls_mod_lock); return rc; }