From patchwork Sat Oct 4 20:30:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 38353 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AF58C203AD for ; Sat, 4 Oct 2014 20:30:57 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id n3sf511447wiv.4 for ; Sat, 04 Oct 2014 13:30:56 -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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=HbKbxYfz5QXqhyvU91LuYLt57R7mop/V/5thNph3AzM=; b=f8v5TEmxW33QS0mSso/5x46A6NcjB/zCC/HGxtZKY1tCYQ3Nswa68DxbsLGBJDHwOz GNT8vFDTLvgIrkx8Z7s0KXVZQ0SiMfXf80NEp2WEHZgQlVeEnGs3T4x9iFyzNdYBod3W NAmaWfsP1CCG7/jIA6JnAuzwGGMeU4sCPSnFztYCPg0zlIJ1Kz/o2F3t0mrwnlr/E0d3 DiLSAO9Dexs/wPEULIIg3L/oiN7V5jJlO96aXFyp8RuyffFMiXOhfVkp1y2eONthug/7 COVVtT1j6bgW0JT75fW6QJBBhwqHjbopCKNBQGWIiPqGDccbBWInklRjpvzTLQqqb6i/ jDKg== X-Gm-Message-State: ALoCoQl6CbERiGgR7FPrMSuUCt6N99ww8fn0IuNVRDDcJvjVi6efaHAAyOLeUVXwiqQtD2YOI8vI X-Received: by 10.112.168.225 with SMTP id zz1mr35148lbb.8.1412454656896; Sat, 04 Oct 2014 13:30:56 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.65 with SMTP id 1ls460440las.63.gmail; Sat, 04 Oct 2014 13:30:56 -0700 (PDT) X-Received: by 10.152.8.9 with SMTP id n9mr14733309laa.2.1412454656625; Sat, 04 Oct 2014 13:30:56 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by mx.google.com with ESMTPS id sf5si6955195lbb.46.2014.10.04.13.30.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 04 Oct 2014 13:30:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so2589827lbv.12 for ; Sat, 04 Oct 2014 13:30:56 -0700 (PDT) X-Received: by 10.152.204.231 with SMTP id lb7mr14526589lac.44.1412454656548; Sat, 04 Oct 2014 13:30:56 -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 of9csp76222lbb; Sat, 4 Oct 2014 13:30:55 -0700 (PDT) X-Received: by 10.70.137.101 with SMTP id qh5mr8707567pdb.76.1412454654281; Sat, 04 Oct 2014 13:30:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pl6si7343357pdb.111.2014.10.04.13.30.53 for ; Sat, 04 Oct 2014 13:30:54 -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 S1751094AbaJDUax (ORCPT + 5 others); Sat, 4 Oct 2014 16:30:53 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:52691 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750956AbaJDUaw (ORCPT ); Sat, 4 Oct 2014 16:30:52 -0400 Received: by mail-wi0-f170.google.com with SMTP id hi2so3947897wib.1 for ; Sat, 04 Oct 2014 13:30:51 -0700 (PDT) X-Received: by 10.195.12.103 with SMTP id ep7mr5304803wjd.121.1412454651091; Sat, 04 Oct 2014 13:30:51 -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 pc6sm11872820wjb.43.2014.10.04.13.30.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Oct 2014 13:30:49 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id D88D1C41FF1; Sat, 4 Oct 2014 13:30:13 -0700 (PDT) From: Grant Likely To: devicetree@vger.kernel.org Cc: Grant Likely , Pantelis Antoniou Subject: [PATCH v2 4/6] of/selftest: Add a test for duplicate phandles Date: Sat, 4 Oct 2014 21:30:00 +0100 Message-Id: <1412454602-28518-4-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412454602-28518-1-git-send-email-grant.likely@linaro.org> References: <1412454602-28518-1-git-send-email-grant.likely@linaro.org> 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.181 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 252a7eda8d6a..4f83e97f8788 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_debug("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();