From patchwork Wed Jun 6 00:46:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925683 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="lrKXkmJ+"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r053w4kz9s08 for ; Wed, 6 Jun 2018 10:58:45 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 34DC2C21FCA; Wed, 6 Jun 2018 00:51:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 31AD1C21FCF; Wed, 6 Jun 2018 00:48:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 155C9C21F3A; Wed, 6 Jun 2018 00:48:10 +0000 (UTC) Received: from mail-io0-f196.google.com (mail-io0-f196.google.com [209.85.223.196]) by lists.denx.de (Postfix) with ESMTPS id B39DFC21F99 for ; Wed, 6 Jun 2018 00:48:06 +0000 (UTC) Received: by mail-io0-f196.google.com with SMTP id s26-v6so5650245ioj.4 for ; Tue, 05 Jun 2018 17:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CsSGLed/ibfsyPX8A6nmJyJPehwHr6fuNr7MMw5FSSY=; b=lrKXkmJ+TPI9eH378H/C5UaUWJFCsqLvlc+Q4OKFikyHCHcnU4zNYtV3uFHGnw+I9U l7ytpco79CwobDjzg6DGSjimthViOMkThm7axKAUJfI10jH4egGKiGNQvFZP+aQCna1L iw0kKDa//XmLdDWp/Arxrrr3t6DzVV2icNCA5m2cvxJTxzArwOodV/hSxfG5LPRDZj30 pDS98xo6H9G7s9pqu+SNuxqJiIBNgkhhwC6g29u5PBRaLZfG4l4kyt5kZvChXKajb6s2 qTCCEiFSGsszWQrAnbNoKf7Yzp6nw66EKb5lM56Vf1bMTC2ZdJ5ZwES6nNbDei55pbT2 iQGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=CsSGLed/ibfsyPX8A6nmJyJPehwHr6fuNr7MMw5FSSY=; b=hM7fSBHTGZ83JgkDAgdwtDZbsKn4U+XJUMNHENqYrr/sb/tpxZpxj6hFKbnK8Pe31E VCNvX/jEAoCa0n3cOou2m8rGpRh4gE5kPL+PEfPBhcnn3d6/l2mYQyE/Z8QhCetSTL0d VgaT8gtO2HkhU3DgxXSYg3TIFZOqFvOLLgkdQEwEwnNTCqI4RYjpC0YzwFAjR56gOcPK 0+MqORidGFWsqbWKozqHHfkeCCB/q08qIic1xU/Obj7DVlNDwFOaxeLBYY1HGyWxQRoF JR8sy0vyuGJ5FB19QZ5Wu/xW7ZQNwV7E0uEzJ/7EHi8gcnL6Ta2OjkyQZOznZMVSBLRy JR5A== X-Gm-Message-State: APt69E2nzi9+o3/Aa6eFWE8+S49/MmxillL3cXvPS05UF2MVyNi1WhTy 9Yync9qjiL7nPHJSMJBJX6wvqQ== X-Google-Smtp-Source: ADUXVKK5MYWMCzpx4TLEfIJGIHwy/NU9NbsEUB/8jMnhXGmtZOHB/StdconAuQF3iDPgBfjvs9sdbA== X-Received: by 2002:a6b:c38b:: with SMTP id t133-v6mr835528iof.197.1528246085175; Tue, 05 Jun 2018 17:48:05 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id z11-v6sm4427225ioc.8.2018.06.05.17.48.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:04 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id C1B961409F9; Tue, 5 Jun 2018 18:48:02 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:53 -0600 Message-Id: <20180606004705.79641-18-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 17/29] dtoc: Fix Fdt.GetNode() to handle a missing node X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At present the algortihm is not correct since it will return the root node if the requested node is not found and there are no slashes in the requested node name. Fix this and add a test. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 5 ++++- tools/dtoc/test_fdt.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 2d7b6328f11..fc8aeb81de5 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -324,7 +324,10 @@ class Fdt: Node object, or None if not found """ node = self._root - for part in path.split('/')[1:]: + parts = path.split('/') + if len(parts) < 2: + return None + for part in parts[1:]: node = node._FindNode(part) if not node: return None diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index cd86144896f..78afb33b056 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -77,6 +77,7 @@ class TestFdt(unittest.TestCase): node = self.dtb.GetNode('/i2c@0/pmic@9') self.assertTrue(isinstance(node, fdt.Node)) self.assertEqual('pmic@9', node.name) + self.assertEqual(None, self.dtb.GetNode('/i2c@0/pmic@9/missing')) def testFlush(self): """Check that we can flush the device tree out to its file""" @@ -177,6 +178,9 @@ class TestProp(unittest.TestCase): self.node = self.dtb.GetNode('/spl-test') self.fdt = self.dtb.GetFdtObj() + def testMissingNode(self): + self.assertEqual(None, self.dtb.GetNode('missing')) + def testPhandle(self): dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts') node = dtb.GetNode('/phandle-source')