From patchwork Wed Jul 18 02:38:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 171595 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 8458A2C047D for ; Wed, 18 Jul 2012 12:38:57 +1000 (EST) Received: from mail-ob0-f179.google.com (mail-ob0-f179.google.com [209.85.214.179]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 29C132C00B4; Wed, 18 Jul 2012 12:38:24 +1000 (EST) Received: by obbeh20 with SMTP id eh20so1356694obb.38 for ; Tue, 17 Jul 2012 19:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=0eJg5S7fqjYtLtT4w+Zg9gJgybiFAiUPABA1YjgvGmU=; b=GfY2ogm0JhTeGggOIUetckGgyn65jOGuwTWAcFcf3VJrxTdsOfGwf1x64gdOU3c3Eq rNIp8Ao0noqV70MESLtlj1OwBpc8co8TSi+ztvCDMOZndhxNm65Zc+N/r/MzvzIqIS26 yZkwFFnsMiTPCy6PMXtgEF8pW5Iu2M1F8eixzskhEhKmmZNEzxEBO1tLjr/o2NyDyO4A k69t5VxTQ1FoDVjcqUtcBcZkrHIsqz1INbL6VeyENc/+GX9JYeQgjItmnwBL60GaPG0R 7pJBGU/q/gphwiu+XbzS0XZzZtG5bGvE1fCoE3oT6QhS5eZi4Sy3ZQQMLybvKadiRYsd 2SaA== Received: by 10.182.144.68 with SMTP id sk4mr6806112obb.0.1342579101425; Tue, 17 Jul 2012 19:38:21 -0700 (PDT) Received: from [192.168.1.103] (65-36-72-55.dyn.grandenetworks.net. [65.36.72.55]) by mx.google.com with ESMTPS id l9sm12742368oeg.3.2012.07.17.19.38.19 (version=SSLv3 cipher=OTHER); Tue, 17 Jul 2012 19:38:20 -0700 (PDT) Message-ID: <50062199.7090904@gmail.com> Date: Tue, 17 Jul 2012 21:38:17 -0500 From: Rob Herring User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Scott Wood Subject: Re: [PATCH] of: require a match on all fields of of_device_id References: <20120718011151.GA6119@tyr.buserror.net> In-Reply-To: <20120718011151.GA6119@tyr.buserror.net> Cc: devicetree-discuss@lists.ozlabs.org, Thierry Reding , linuxppc-dev@lists.ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 07/17/2012 08:11 PM, Scott Wood wrote: > Commit 107a84e61cdd3406c842a0e4be7efffd3a05dba6 ("of: match by compatible > property first") breaks the gianfar ethernet driver found on various > Freescale PPC chips. You do know this is reverted, right? > > There are, for unfortunate historical reasons, two nodes with a > compatible of "gianfar". One has a device_type of "network" and the > other has device_type of "mdio". The match entries look like this: > >> { >> .type = "mdio", >> .compatible = "gianfar", >> }, > > and > >> { >> .type = "network", >> .compatible = "gianfar", >> }, > > With the above patch, both nodes get probed by the first driver, because > nothing else in the match struct is looked at if there's a compatible > match. > > Signed-off-by: Scott Wood Here's my fix (untested) which is a bit simpler. I'm assuming if we care about which compatible string we are matching to, then we require name and type are blank and we only care about compatible strings. @@ -557,7 +560,10 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches, if (matches->type[0]) match &= node->type && !strcmp(matches->type, node->type); - if (match && !matches->compatible[0]) + if (matches->compatible[0]) + match &= of_device_is_compatible(node, + matches->compatible); + if (match) return matches; matches++; } > --- > drivers/of/base.c | 44 ++++++++++++++++++++++++++++++++------------ > 1 file changed, 32 insertions(+), 12 deletions(-) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index bc86ea2..4e707cc 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -511,14 +511,37 @@ out: > } > EXPORT_SYMBOL(of_find_node_with_property); > > -static const struct of_device_id *of_match_compat(const struct of_device_id *matches, > - const char *compat) > +/* > + * Tell if an device_node matches the non-compatible fields of > + * a specific of_match element. > + */ > +static bool of_match_one_noncompat(const struct of_device_id *match, > + const struct device_node *node) > +{ > + bool is_match = true; > + > + if (match->name[0]) > + is_match &= node->name && !strcmp(match->name, node->name); > + if (match->type[0]) > + is_match &= node->type && !strcmp(match->type, node->type); > + > + return is_match; > +} > + > +/* > + * Find an OF match using the supplied compatible string, rather than > + * the node's entire string list. > + */ > +static const struct of_device_id *of_match_compat( > + const struct of_device_id *matches, const char *compat, > + const struct device_node *node) > { > while (matches->name[0] || matches->type[0] || matches->compatible[0]) { > const char *cp = matches->compatible; > int len = strlen(cp); > > - if (len > 0 && of_compat_cmp(compat, cp, len) == 0) > + if (len > 0 && of_compat_cmp(compat, cp, len) == 0 && > + of_match_one_noncompat(matches, node)) > return matches; > > matches++; > @@ -544,23 +567,20 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches, > return NULL; > > of_property_for_each_string(node, "compatible", prop, cp) { > - const struct of_device_id *match = of_match_compat(matches, cp); > + const struct of_device_id *match = > + of_match_compat(matches, cp, node); > if (match) > return match; > } > > while (matches->name[0] || matches->type[0] || matches->compatible[0]) { > - int match = 1; > - if (matches->name[0]) > - match &= node->name > - && !strcmp(matches->name, node->name); > - if (matches->type[0]) > - match &= node->type > - && !strcmp(matches->type, node->type); > - if (match && !matches->compatible[0]) > + if (of_match_one_noncompat(matches, node) && > + !matches->compatible[0]) > return matches; > + > matches++; > } > + > return NULL; > } > EXPORT_SYMBOL(of_match_node); > diff --git a/drivers/of/base.c b/drivers/of/base.c index eada3f4..6e10004 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -518,6 +518,9 @@ static const struct of_device_id *of_match_compat(const struct of_device_id *mat const char *cp = matches->compatible; int len = strlen(cp); + if (matches->name[0] || matches->type[0]) + continue; + if (len > 0 && of_compat_cmp(compat, cp, len) == 0) return matches;