From patchwork Tue Dec 13 21:38:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 131194 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 63E821007D3 for ; Wed, 14 Dec 2011 08:38:15 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755390Ab1LMViK (ORCPT ); Tue, 13 Dec 2011 16:38:10 -0500 Received: from mail-fx0-f46.google.com ([209.85.161.46]:35823 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754630Ab1LMViH (ORCPT ); Tue, 13 Dec 2011 16:38:07 -0500 Received: by faar15 with SMTP id r15so662556faa.19 for ; Tue, 13 Dec 2011 13:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:x-mailer:content-transfer-encoding:mime-version; bh=lqeZIomSPbv4aB0+Cqf56LHY+go5gH70/JCVyLc7TqY=; b=x9ujx5SXLtAi2NVdGPlDuAyFsjxUVc+SdAwCTpLfFupUABEcHaAYVOBtvsN09TBzv3 9hW6gUDqt7YjJ7A3Y8BqwX7b+2L7lUuJXKy22Ec+/5n0iS8ve9d/twxjf2zgkuZaDzNT OM3OTHosEUQ/YG6Nw/POu+8cEfvxa+XG0dWgo= Received: by 10.180.98.138 with SMTP id ei10mr404154wib.52.1323812286241; Tue, 13 Dec 2011 13:38:06 -0800 (PST) Received: from [192.168.1.21] ([86.72.144.94]) by mx.google.com with ESMTPS id gb16sm546607wbb.12.2011.12.13.13.38.04 (version=SSLv3 cipher=OTHER); Tue, 13 Dec 2011 13:38:05 -0800 (PST) Message-ID: <1323812280.2846.9.camel@edumazet-laptop> Subject: [PATCH net-next] rtnetlink: rtnl_link_register() sanity test From: Eric Dumazet To: David Miller Cc: alex.bluesman.smirnov@gmail.com, netdev@vger.kernel.org Date: Tue, 13 Dec 2011 22:38:00 +0100 In-Reply-To: <20111213.160810.785264274549847462.davem@davemloft.net> References: <1323808281-9967-1-git-send-email-alex.bluesman.smirnov@gmail.com> <20111213.160810.785264274549847462.davem@davemloft.net> X-Mailer: Evolution 3.2.1- Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Before adding a struct rtnl_link_ops into link_ops list, check it doesnt clash with a prior one. Based on a previous patch from Alexander Smirnov Signed-off-by: Eric Dumazet CC: Alexander Smirnov --- net/core/rtnetlink.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 9083e82..dbf2dda 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -273,6 +273,17 @@ EXPORT_SYMBOL_GPL(rtnl_unregister_all); static LIST_HEAD(link_ops); +static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind) +{ + const struct rtnl_link_ops *ops; + + list_for_each_entry(ops, &link_ops, list) { + if (!strcmp(ops->kind, kind)) + return ops; + } + return NULL; +} + /** * __rtnl_link_register - Register rtnl_link_ops with rtnetlink. * @ops: struct rtnl_link_ops * to register @@ -285,6 +296,9 @@ static LIST_HEAD(link_ops); */ int __rtnl_link_register(struct rtnl_link_ops *ops) { + if (rtnl_link_ops_get(ops->kind)) + return -EEXIST; + if (!ops->dellink) ops->dellink = unregister_netdevice_queue; @@ -351,17 +365,6 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops) } EXPORT_SYMBOL_GPL(rtnl_link_unregister); -static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind) -{ - const struct rtnl_link_ops *ops; - - list_for_each_entry(ops, &link_ops, list) { - if (!strcmp(ops->kind, kind)) - return ops; - } - return NULL; -} - static size_t rtnl_link_get_size(const struct net_device *dev) { const struct rtnl_link_ops *ops = dev->rtnl_link_ops;