From patchwork Thu Oct 2 12:11:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 38291 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A6EB720BF9 for ; Thu, 2 Oct 2014 12:12:27 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id y10sf1083720wgg.6 for ; Thu, 02 Oct 2014 05:12:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=XAIby5Pc6muBsP+Q9yFxLN5Wbs3e/ihJDhtFJyV7QWk=; b=RYYcioIkeLWS3KqazTnILwz8rbNcUGDtcDUekTsze0P/ByUOofX7fmqQMompGpMcul i4MAfGlTdkbZ3jxzaGNg4TY/Co9dsUTse/SUvpu0b6Lof84Q8QQ6vPolZBQsb3iZj58W AZbjVARMshajuy71h3VZxpm2AkNub3VadexVouecP7eNn1EuWl6vaMWlsxmOkSoR92c1 VgHt4bX51QMMz6GxLoqXiDawg5/eGlnPwAuLRMlS8XBgmL6Uu/oJ5rHNQavOgkbGabqy OFbsUQBRAx/1Xt5iK1PiWgL2VPUeEyWqisxEW8473lbJKH97wEM3lWy8OoVT8/JkSmGe evmg== X-Gm-Message-State: ALoCoQkd5DrzCWBUftGVSYnswhBrjOBEASyOm5TxZB/wi7x1WV6lPx/U90KFTIsWpQlyTJ+1HfAZ X-Received: by 10.112.52.165 with SMTP id u5mr555057lbo.12.1412251946777; Thu, 02 Oct 2014 05:12:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.229 with SMTP id h5ls284417lam.4.gmail; Thu, 02 Oct 2014 05:12:26 -0700 (PDT) X-Received: by 10.152.234.76 with SMTP id uc12mr62515323lac.50.1412251946108; Thu, 02 Oct 2014 05:12:26 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com [209.85.217.173]) by mx.google.com with ESMTPS id w2si6282630lbb.75.2014.10.02.05.12.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 02 Oct 2014 05:12:25 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id 10so2104861lbg.18 for ; Thu, 02 Oct 2014 05:12:25 -0700 (PDT) X-Received: by 10.112.130.226 with SMTP id oh2mr24803695lbb.100.1412251945610; Thu, 02 Oct 2014 05:12:25 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp40396lbb; Thu, 2 Oct 2014 05:12:24 -0700 (PDT) X-Received: by 10.68.65.6 with SMTP id t6mr44981980pbs.138.1412251943722; Thu, 02 Oct 2014 05:12:23 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rc5si3780417pbc.60.2014.10.02.05.12.23 for ; Thu, 02 Oct 2014 05:12:23 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752381AbaJBMMW (ORCPT + 5 others); Thu, 2 Oct 2014 08:12:22 -0400 Received: from mail-wi0-f173.google.com ([209.85.212.173]:50993 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751815AbaJBMMV (ORCPT ); Thu, 2 Oct 2014 08:12:21 -0400 Received: by mail-wi0-f173.google.com with SMTP id bs8so3737670wib.6 for ; Thu, 02 Oct 2014 05:12:20 -0700 (PDT) X-Received: by 10.180.93.99 with SMTP id ct3mr3761664wib.0.1412251940377; Thu, 02 Oct 2014 05:12:20 -0700 (PDT) Received: from trevor.secretlab.ca (host86-166-87-213.range86-166.btcentralplus.com. [86.166.87.213]) by mx.google.com with ESMTPSA id fa7sm4398819wjd.27.2014.10.02.05.12.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Oct 2014 05:12:19 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 39B06C417B4; Thu, 2 Oct 2014 05:11:51 -0700 (PDT) From: Grant Likely To: devicetree@vger.kernel.org Cc: Grant Likely , Pantelis Antoniou Subject: [PATCH] of/selftest: Add a test for duplicate phandles Date: Thu, 2 Oct 2014 13:11:49 +0100 Message-Id: <1412251909-5579-1-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , All phandles in the tree should be unique. Add a testcase to make sure that this is so. Note: this testcase fails on the current kernel because the selftest code itself ends up adding duplicate phandles. Before this testcase is merged the selftest code needs to be modified to resolve phandles before adding them. Signed-off-by: Grant Likely Cc: Pantelis Antoniou --- drivers/of/selftest.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 953b5eb1d09d..634eb79bfe47 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -192,6 +193,51 @@ static void __init of_selftest_check_tree_linkage(void) pr_info("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count); } +struct node_hash { + struct hlist_node node; + struct device_node *np; +}; + +static void __init of_selftest_check_phandles(void) +{ + struct device_node *np; + struct node_hash *nh; + struct hlist_node *tmp; + int i, dup_count = 0, phandle_count = 0; + DECLARE_HASHTABLE(ht, 8); + + hash_init(ht); + for_each_of_allnodes(np) { + if (!np->phandle) + continue; + + hash_for_each_possible(ht, nh, node, np->phandle) { + if (nh->np->phandle == np->phandle) { + pr_info("Duplicate phandle! %i used by %s and %s\n", + np->phandle, nh->np->full_name, np->full_name); + dup_count++; + break; + } + } + + nh = kzalloc(sizeof(*nh), GFP_KERNEL); + if (WARN_ON(!nh)) + return; + + nh->np = np; + hash_add(ht, &nh->node, np->phandle); + phandle_count++; + } + selftest(dup_count == 0, "Found %i duplicates in %i phandles\n", + dup_count, phandle_count); + + /* Clean up */ + hash_for_each_safe(ht, i, tmp, nh, node) { + hash_del(&nh->node); + kfree(nh); + } +} + static void __init of_selftest_parse_phandle_with_args(void) { struct device_node *np; @@ -825,6 +871,7 @@ static int __init of_selftest(void) pr_info("start of selftest - you will see error messages\n"); of_selftest_check_tree_linkage(); + of_selftest_check_phandles(); of_selftest_find_node_by_name(); of_selftest_dynamic(); of_selftest_parse_phandle_with_args();