Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1502CC77B78 for ; Thu, 4 May 2023 12:22:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1033081DCF; Thu, 4 May 2023 14:22:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="hwLFy3IE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 756F4826B2; Thu, 4 May 2023 14:22:31 +0200 (CEST) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4669A810F5 for ; Thu, 4 May 2023 14:22:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eugen.hristev@collabora.com Received: from eugen-station.. (unknown [82.76.24.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madras.collabora.co.uk (Postfix) with ESMTPSA id 6BE8266031D7; Thu, 4 May 2023 13:22:28 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1683202948; bh=21Nqzp5IUpg/d8Gd2Hl24cDM3K6jt4ObhGT+bhHzEig=; h=From:To:Cc:Subject:Date:From; b=hwLFy3IE8uprJkWaw3RubLc9nXUdhE1NLrQwldGT6OwJpAXhK4jL6pSySUVkAa2LQ T+4Sl14owqe49HvLZOZQ0A67U1pNCKOcxy5SDIdGuDVfz2NDDXHBXRD8xGftTl2mpN UUMAA5OVCbrNyfiUZDXf0RC5xfUqgdhb1i3hUnlQxeZEYp3jCOIZXb5j+44KBbabPc Pgv9wCe8Uwa72l9JOJrWcfV5QA0Xa2ZP0xU1NZxWD4ef4ahlzglaKVA816AQLkJiIV xoGYlfJMqnjN5pdu6ODM56nQVpflCkrTIIBKvWrSpEV461FQWqEyvo3PeJtvBey+ES kyKMihKinV2uQ== From: Eugen Hristev To: sjg@chromium.org, u-boot@lists.denx.de Cc: Eugen Hristev Subject: [PATCH] dm: core: of_access: fix return value in of_property_match_string Date: Thu, 4 May 2023 15:22:21 +0300 Message-Id: <20230504122221.143292-1-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean of_property_match_string calls of_find_property to search for the string property. If the device node does not exist, of_find_property returns NULL, and of_property_match_string returns -EINVAL, which is correct. However, if the device node exists, but the property is not found, of_find_property still returns NULL, but it will place -FDT_ERR_NOTFOUND in the *lenp variable. of_property_match_string does not use the lenp parameter, thus this error case is being lost, and treated as if the node is NULL, and returns -EINVAL, which is incorrect. The callers of of_property_match_string treat the error differently if the return value is -EINVAL or -ENOENT, e.g. in dwc3 driver: ret = generic_phy_get_by_name(dev, "usb3-phy", &phy); if (!ret) { ret = generic_phy_init(&phy); if (ret) return ret; } else if (ret != -ENOENT && ret != -ENODATA) { debug("could not get phy (err %d)\n", ret); return ret; } else { phy.dev = NULL; } So the caller drivers will just consider the property missing if -ENOENT is returned, versus the case of -EINVAL, which means something else. To fix this situation, changed the code to call the of_find_property with the right third argument to catch this error code and treat it accordingly. Signed-off-by: Eugen Hristev --- drivers/core/of_access.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 81a307992c01..57f10445b122 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -593,11 +593,14 @@ int of_read_u64(const struct device_node *np, const char *propname, u64 *outp) int of_property_match_string(const struct device_node *np, const char *propname, const char *string) { - const struct property *prop = of_find_property(np, propname, NULL); + int len = 0; + const struct property *prop = of_find_property(np, propname, &len); size_t l; int i; const char *p, *end; + if (!prop && len == -FDT_ERR_NOTFOUND) + return -ENOENT; if (!prop) return -EINVAL; if (!prop->value) -- 2.34.1