From patchwork Tue Dec 3 13:52:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Hesselbarth X-Patchwork-Id: 3276191 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2EBE4C0D4A for ; Tue, 3 Dec 2013 13:52:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9D4D2037A for ; Tue, 3 Dec 2013 13:52:56 +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 1B34B20171 for ; Tue, 3 Dec 2013 13:52:52 +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 1VnqP1-0006Ii-CU; Tue, 03 Dec 2013 13:52:39 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VnqOy-0004d9-UP; Tue, 03 Dec 2013 13:52:36 +0000 Received: from mail-ea0-x234.google.com ([2a00:1450:4013:c01::234]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VnqOv-0004bo-M5 for linux-arm-kernel@lists.infradead.org; Tue, 03 Dec 2013 13:52:35 +0000 Received: by mail-ea0-f180.google.com with SMTP id f15so9854855eak.25 for ; Tue, 03 Dec 2013 05:52:09 -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:in-reply-to:references; bh=TLRLf19dc8Ym5nQlpAU5NT7SDhpkDBq8tGTVbv0SXh4=; b=SaGKOLQNAxbShpLbNDrwe7dyu/abyy7cWa9SCMaO2UiQuYQK9krg/qp/tUp4r1ABx3 EEuaBTyD1fAdF8Jr8PX4o+TipjB5GhrAGzEJM0Y1mRVSHnLAtujmhvTPcyASv+CdACqy ti0b5Jeehko6sHxVIVGcV2i1nXzIxoyS/eYUsReqHkwSP9EY5J7Yeq74lK+9fa0f+xyY zqe2VuGmxzfG+uvMPjs2rz5q3G/b/My2yhPgwthGBml5z4TpmEV5RqNPE4sx3XVaPTwX PG4GT8R2t8+c8xwz1JZP69TIMXU3YptPGEEx+xIX5wBJ4lgKvwzpKXN5mNMzquKK3Bm9 PkAA== X-Received: by 10.14.194.1 with SMTP id l1mr2890847een.103.1386078729325; Tue, 03 Dec 2013 05:52:09 -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 1sm82642627eeg.4.2013.12.03.05.52.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Dec 2013 05:52:08 -0800 (PST) From: Sebastian Hesselbarth To: Sebastian Hesselbarth Subject: [PATCH v2] OF: base: match each node compatible against all given matches first Date: Tue, 3 Dec 2013 14:52:00 +0100 Message-Id: <1386078720-8756-1-git-send-email-sebastian.hesselbarth@gmail.com> In-Reply-To: <1385663785-8643-1-git-send-email-sebastian.hesselbarth@gmail.com> References: <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-20131203_085233_852063_D1FD2C4C X-CRM114-Status: GOOD ( 16.00 ) X-Spam-Score: -2.0 (--) Cc: devicetree@vger.kernel.org, Russell King , Benjamin Herrenschmidt , Meelis Roos , linux-kernel@vger.kernel.org, Rob Herring , Scott Wood , Thierry Reding , Marc Kleine-Budde , Grant Likely , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth 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 --- Changelog: v1->v2: - Allow checks against nodes with no compatible (Reported by Rob Herring) - Add some comments Cc: Grant Likely Cc: Rob Herring Cc: Benjamin Herrenschmidt Cc: Russell King Cc: Thierry Reding Cc: Meelis Roos Cc: Marc Kleine-Budde Cc: Scott Wood Cc: devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- drivers/of/base.c | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index f807d0e..8d007d8 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -731,24 +731,42 @@ 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); + do { + const struct of_device_id *m = matches; + + /* Check against matches with current compatible string */ + 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 &= cp + && !of_compat_cmp(m->compatible, cp, + strlen(m->compatible)); + if (match) + return m; + m++; + } + + /* Get node's next compatible string */ + if (cp) { + l = strlen(cp) + 1; + cp += l; + cplen -= l; + } + } while (cp && (cplen > 0)); + return NULL; } @@ -757,7 +775,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)