From patchwork Sat Dec 7 04:41:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1205335 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.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" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="U1Fyh6kj"; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47VH344HKQz9sPL for ; Sat, 7 Dec 2019 15:46:08 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9112B80E97; Sat, 7 Dec 2019 05:46:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="U1Fyh6kj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 58F388135C; Sat, 7 Dec 2019 05:46:03 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2FB8A815E1 for ; Sat, 7 Dec 2019 05:45:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x144.google.com with SMTP id z90so8108336ilc.8 for ; Fri, 06 Dec 2019 20:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bnEGgN5gA6QjSTiaUuR5Ld3qa7LImH89051HLKWMgNU=; b=U1Fyh6kj2DHfC6JYpeeW14sYJDZK38qPY9+ZIW0mI7Oo1g/APgCjr1eDkqPXwWD4OM WQJdbYMjk5dste8piTd8/GhZm8l0leRbKD+OyUoi5h5v+Un+FOZTaSHm7XV3wxHXicl4 vhJ7iR2MiXgqVdUZQi56qa7BFxPHaXyZkvTr4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bnEGgN5gA6QjSTiaUuR5Ld3qa7LImH89051HLKWMgNU=; b=fu8mSu40OUTS6ruCOQ9R2XwdMWW3H9smUhVdKg08IoRDcXYYuzLsZo9aLL01PxETIv 2uBITRYbnepaaACp/7+DoF0umAeivglLM6lh97Su9WexUJl+7R/FBgxmAru9ro6aazNl W3j4i3kMEhZ9W9gPD3tWsqq2pDKHVaL0+PX6FgAZ8IOugvCPA/KJYAwHxRuQihGPyVRh cZ9D0Su1rsGLddqvuu4I2o0Y1E9wyvACB/jk1hd6TGQZrUngrZ5a86CVcUk8ntXSVIIM CDLr6fGXo7a7WqPY2MmSZtHO8h02HdJ3emCQymhIZp60t8OBo4QvfIHFKt9+U0ZVh6bx VMEw== X-Gm-Message-State: APjAAAXiTY+ATxBsUZTYHnvAvvSAQM6OU4ALLAHJDkpg6Rzk4OXp0K0I a2jEeOJWO8h4r0eKCJX00FylpTvFBG8= X-Google-Smtp-Source: APXvYqyJUd9uIqS7UhsaO5iZi5eF6bZFDBzzWdoWekhkmlwq9sEEZt9DhOi1bZZlmXBg6jqJ4TGzfQ== X-Received: by 2002:a92:6908:: with SMTP id e8mr17314970ilc.56.1575693957970; Fri, 06 Dec 2019 20:45:57 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id o7sm4549410ilo.58.2019.12.06.20.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2019 20:45:57 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH v6 003/102] dm: core: Fix offset_to_ofnode() with invalid offset Date: Fri, 6 Dec 2019 21:41:36 -0700 Message-Id: <20191206213936.v6.3.Idd33327507b1e9fbd348a5424bb3f627ab9f78c7@changeid> X-Mailer: git-send-email 2.24.0.393.g34dc348eaf-goog In-Reply-To: <20191207044315.51770-1-sjg@chromium.org> References: <20191207044315.51770-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean If the offset is -1 this function correctly sets up a null ofnode. But if the offset is any other negative number (e.g. -FDT_ERR_BADPATH) then it does the wrong thing. An offset of -1 in ofnode indicates that the ofnode is not valid. Any other negative value is not handled by ofnode_valid(). We could of course change that function, but it seems much better to always use the same value for an invalid node. Fix it by setting the offset to -1 if it is invalid for any reason. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v6: None Changes in v5: None Changes in v4: - Update the commit message to be clearer, fix 'correct' typo Changes in v3: None Changes in v2: None include/dm/ofnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 5c4cbf0998..4282169706 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -118,7 +118,7 @@ static inline ofnode offset_to_ofnode(int of_offset) if (of_live_active()) node.np = NULL; else - node.of_offset = of_offset; + node.of_offset = of_offset >= 0 ? of_offset : -1; return node; }