From patchwork Thu Nov 28 18:36:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Hesselbarth X-Patchwork-Id: 3255351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6B58F9F36A for ; Thu, 28 Nov 2013 18:45:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 36E0F20667 for ; Thu, 28 Nov 2013 18:37:58 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF73320668 for ; Thu, 28 Nov 2013 18:37:56 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vm6Sq-0003rF-1X; Thu, 28 Nov 2013 18:37:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vm6Sf-0000fU-1x; Thu, 28 Nov 2013 18:37:13 +0000 Received: from mail-ea0-x233.google.com ([2a00:1450:4013:c01::233]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vm6SN-0000ch-MV for linux-arm-kernel@lists.infradead.org; Thu, 28 Nov 2013 18:36:57 +0000 Received: by mail-ea0-f179.google.com with SMTP id r15so6044487ead.24 for ; Thu, 28 Nov 2013 10:36:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=7cMweDmxOavk93HhgZBfFqtGC+gSg8Ofd8DMd9YPXmU=; b=LHbo9M+2FsAQ9dkiUrvqOjDgOeCH14khx5jmJAWazYHon7+GaS8fP6Ac98g3dKTc1Z VNo5uVFvqOOnzT4HdM64cYd63Gc42Y7IRqUC3Acy95nq4NHNr+bMeQPLLhgxcPtXo4qL XOZ3xQeLrFBNtF3/gZ8fOIUt2S71USfV2CNukKGHtjxLobH6DbIPOTeN7gIkjz3uvLWQ +HXZyzCMnuw6QCVuZY2Yelup5V2NxWEciE64jf06cC4arMLdrnsiQrp50TXzIwCdN5Py OzPgFutoqlGjkQEnjYBVu0+b85THMmcRNFyqATkZ03DVBb4AGQbo3jIs28d/Qs7KhVgg AGBg== X-Received: by 10.15.49.195 with SMTP id j43mr6765463eew.40.1385663793523; Thu, 28 Nov 2013 10:36:33 -0800 (PST) Received: from topkick.lan (dslc-082-083-251-183.pools.arcor-ip.net. [82.83.251.183]) by mx.google.com with ESMTPSA id c46sm19988485eep.17.2013.11.28.10.36.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Nov 2013 10:36:32 -0800 (PST) From: Sebastian Hesselbarth To: Sebastian Hesselbarth Subject: [PATCH] OF: base: match each node compatible against all given matches first Date: Thu, 28 Nov 2013 19:36:25 +0100 Message-Id: <1385663785-8643-1-git-send-email-sebastian.hesselbarth@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131128_133655_956869_0FEB0B28 X-CRM114-Status: GOOD ( 14.10 ) X-Spam-Score: -2.0 (--) Cc: devicetree@vger.kernel.org, Russell King , Benjamin Herrenschmidt , linux-kernel@vger.kernel.org, Rob Herring , Grant Likely , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, of_match_node compares each given match against all node's compatible strings with of_device_is_compatible. To achieve multiple compatible strings per node with ordering from specific to generic, this requires given matches to be ordered from specific to generic. For most of the drivers this is not true and also an alphabetical ordering is more sane there. Therefore, this patch modifies of_match_node to match each of the node's compatible strings against all given matches first, before checking the next compatible string. This implies that node's compatibles are ordered from specific to generic while given matches can be in any order. Signed-off-by: Sebastian Hesselbarth --- Cc: Grant Likely Cc: Rob Herring Cc: Benjamin Herrenschmidt Cc: Russell King Cc: devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- drivers/of/base.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 7d4c70f..183a9c7 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -713,23 +713,37 @@ static const struct of_device_id *__of_match_node(const struct of_device_id *matches, const struct device_node *node) { + const char *cp; + int cplen, l; + if (!matches) return NULL; - 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 (matches->compatible[0]) - match &= __of_device_is_compatible(node, - matches->compatible); - if (match) - return matches; - matches++; + cp = __of_get_property(node, "compatible", &cplen); + if (!cp) + return NULL; + + while (cplen > 0) { + const struct of_device_id *m = matches; + + while (m->name[0] || m->type[0] || m->compatible[0]) { + int match = 1; + if (m->name[0]) + match &= node->name + && !strcmp(m->name, node->name); + if (m->type[0]) + match &= node->type + && !strcmp(m->type, node->type); + if (m->compatible[0]) + match &= !of_compat_cmp(cp, m->compatible, + strlen(m->compatible)); + if (match) + return m; + m++; + } + l = strlen(cp) + 1; + cp += l; + cplen -= l; } return NULL; } @@ -739,7 +753,10 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches, * @matches: array of of device match structures to search in * @node: the of device structure to match against * - * Low level utility function used by device matching. + * Low level utility function used by device matching. Matching order + * is to compare each of the node's compatibles with all given matches + * first. This implies node's compatible is sorted from specific to + * generic while matches can be in any order. */ const struct of_device_id *of_match_node(const struct of_device_id *matches, const struct device_node *node)