From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jarek Poplawski Subject: [PATCH 2/2] pkt_sched: Add some basic qdisc class ops verification. Was: [PATCH] sfq: add dummy bind/unbind handles Date: Tue, 10 Aug 2010 00:18:48 +0200 Message-ID: <20100809221848.GB18629@del.dom.local> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: David Miller , shemminger@vyatta.com, netdev@vger.kernel.org To: Franchoze Eric Return-path: Received: from mail-bw0-f46.google.com ([209.85.214.46]:53373 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757160Ab0HIWSx (ORCPT ); Mon, 9 Aug 2010 18:18:53 -0400 Received: by mail-bw0-f46.google.com with SMTP id 3so1537659bwz.19 for ; Mon, 09 Aug 2010 15:18:52 -0700 (PDT) Content-Disposition: inline Sender: netdev-owner@vger.kernel.org List-ID: Verify in register_qdisc() some basic qdisc class handlers are present. Signed-off-by: Jarek Poplawski --- diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index b9e8c3b..8ed2f56 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -150,22 +150,34 @@ int register_qdisc(struct Qdisc_ops *qops) if (qops->enqueue == NULL) qops->enqueue = noop_qdisc_ops.enqueue; if (qops->peek == NULL) { - if (qops->dequeue == NULL) { + if (qops->dequeue == NULL) qops->peek = noop_qdisc_ops.peek; - } else { - rc = -EINVAL; - goto out; - } + else + goto out_einval; } if (qops->dequeue == NULL) qops->dequeue = noop_qdisc_ops.dequeue; + if (qops->cl_ops) { + const struct Qdisc_class_ops *cops = qops->cl_ops; + + if (!(cops->get && cops->put)) + goto out_einval; + + if (cops->tcf_chain && !(cops->bind_tcf && cops->unbind_tcf)) + goto out_einval; + } + qops->next = NULL; *qp = qops; rc = 0; out: write_unlock(&qdisc_mod_lock); return rc; + +out_einval: + rc = -EINVAL; + goto out; } EXPORT_SYMBOL(register_qdisc);