From patchwork Fri Sep 25 07:41:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1371087 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=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=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=SqpKAJUy; 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 4ByP5Z4Vt9z9sSf for ; Fri, 25 Sep 2020 17:42:31 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0C453826AC; Fri, 25 Sep 2020 09:41:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.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=st.com header.i=@st.com header.b="SqpKAJUy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E513826CA; Fri, 25 Sep 2020 09:41:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8DAA482517 for ; Fri, 25 Sep 2020 09:41:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08P7boxi018206; Fri, 25 Sep 2020 09:41:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=STMicroelectronics; bh=LIxrBJQBm4w3T13qkqG1ZVR7hNNUbZW5XTySx2iP/B4=; b=SqpKAJUyWM1TvVdhyt39wbvcbEMeXpSLkSNL9BpKr33qGn4X/sGupHze9cTa/gaMMr2c 5taC040riqz+Q8Is8wYEZxZzpNtxotBUTwBCq2g9gy755THy6LWm++71uc8IQwCjc3HJ I0SCJFJh4hs+6Paj2a6ixTA0xxmvbD2Q+yKecsqErDQHPrdZQfpS8kvOqhTCiCG2szcK F2dGd3riiPzyHiZ+dB6HM5q63EhvPlrBTLA23wLRUUsld96AngjJ+Cp9pKanP04C7y4r HodXZPWCKU996qH+RLdNnjZ89+vaBXFX0lx+NlzgKPiufq00KOfn1lPp+ajbCmBuQr96 ZA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 33n748k6t2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 09:41:29 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DDD5810002A; Fri, 25 Sep 2020 09:41:27 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AEB5021FE8A; Fri, 25 Sep 2020 09:41:27 +0200 (CEST) Received: from localhost (10.75.127.46) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 25 Sep 2020 09:41:27 +0200 From: Patrick Delaunay To: CC: Patrick Delaunay , Anatolij Gustschin , Chunfeng Yun , Jaehoon Chung , Jagan Teki , Jean-Jacques Hiblot , Joe Hershberger , Lokesh Vutla , Lukasz Majewski , Marek Vasut , Masahiro Yamada , Neil Armstrong , Peng Fan , Simon Glass , Vignesh Raghavendra , Subject: [PATCH 1/3] dm: add cells_count parameter in *_count_phandle_with_args Date: Fri, 25 Sep 2020 09:41:14 +0200 Message-ID: <20200925074116.16068-1-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-25_02:2020-09-24, 2020-09-25 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean The cell_count argument is required when cells_name is NULL. This patch adds this parameter in live tree API - of_count_phandle_with_args - ofnode_count_phandle_with_args - dev_count_phandle_with_args This parameter solves issue when these API is used to count the number of element of a cell without cell name. This parameter allow to force the size cell. For example: count = dev_count_phandle_with_args(dev, "array", NULL, 3); Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- It is linked to previous serie [1] but it is not a blocking point today as no user use this API with cells_name = NULL + dev_count_phandle_with_args + ofnode_count_phandle_with_args [1/3] was Previously sent in RFC [2] + missing impacts in: drivers/net/designware.c drivers/power/domain/power-domain-uclass.c drivers/usb/host/ohci-da8xx.c drivers/usb/host/ohci-generic.c I also add test in [3/3] for modified API. But I think it is the good time to modify these functions as they are not hugely used. [1] http://patchwork.ozlabs.org/project/uboot/list/?series=200899 "dm: add cells_count parameter in live DT APIs of_parse_phandle_with_args" [2] http://patchwork.ozlabs.org/project/uboot/list/?series=200906&state=* board/st/stm32mp1/stm32mp1.c | 2 +- drivers/clk/clk-uclass.c | 4 ++-- drivers/core/of_access.c | 7 ++++--- drivers/core/ofnode.c | 6 +++--- drivers/core/read.c | 5 +++-- drivers/net/designware.c | 3 ++- drivers/phy/phy-uclass.c | 2 +- drivers/power/domain/power-domain-uclass.c | 2 +- drivers/reset/reset-uclass.c | 2 +- drivers/usb/host/ehci-generic.c | 4 ++-- drivers/usb/host/ohci-da8xx.c | 3 ++- drivers/usb/host/ohci-generic.c | 6 ++++-- include/dm/of_access.h | 4 +++- include/dm/ofnode.h | 3 ++- include/dm/read.h | 8 +++++--- 15 files changed, 36 insertions(+), 25 deletions(-) diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 3b677d339b..03a19af930 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -314,7 +314,7 @@ static int board_check_usb_power(void) * for each of them */ adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd", - "#io-channel-cells"); + "#io-channel-cells", 0); if (adc_count < 0) { if (adc_count == -ENOENT) return 0; diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 934cd5787a..b1d8f1adaf 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -160,7 +160,7 @@ int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk) bulk->count = 0; - count = dev_count_phandle_with_args(dev, "clocks", "#clock-cells"); + count = dev_count_phandle_with_args(dev, "clocks", "#clock-cells", 0); if (count < 1) return count; @@ -195,7 +195,7 @@ static int clk_set_default_parents(struct udevice *dev, int stage) int ret; num_parents = dev_count_phandle_with_args(dev, "assigned-clock-parents", - "#clock-cells"); + "#clock-cells", 0); if (num_parents < 0) { debug("%s: could not read assigned-clock-parents for %p\n", __func__, dev); diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index bcf1644d05..0a12e9b26f 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -756,10 +756,11 @@ int of_parse_phandle_with_args(const struct device_node *np, } int of_count_phandle_with_args(const struct device_node *np, - const char *list_name, const char *cells_name) + const char *list_name, const char *cells_name, + int cell_count) { - return __of_parse_phandle_with_args(np, list_name, cells_name, 0, - -1, NULL); + return __of_parse_phandle_with_args(np, list_name, cells_name, + cell_count, -1, NULL); } static void of_alias_add(struct alias_prop *ap, struct device_node *np, diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 79fcdf5ce2..7d1b89514c 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -432,15 +432,15 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, } int ofnode_count_phandle_with_args(ofnode node, const char *list_name, - const char *cells_name) + const char *cells_name, int cell_count) { if (ofnode_is_np(node)) return of_count_phandle_with_args(ofnode_to_np(node), - list_name, cells_name); + list_name, cells_name, cell_count); else return fdtdec_parse_phandle_with_args(gd->fdt_blob, ofnode_to_offset(node), list_name, cells_name, - 0, -1, NULL); + cell_count, -1, NULL); } ofnode ofnode_path(const char *path) diff --git a/drivers/core/read.c b/drivers/core/read.c index 86f3f88170..076125824c 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -214,10 +214,11 @@ int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, } int dev_count_phandle_with_args(const struct udevice *dev, - const char *list_name, const char *cells_name) + const char *list_name, const char *cells_name, + int cell_count) { return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, - cells_name); + cells_name, cell_count); } int dev_read_addr_cells(const struct udevice *dev) diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 1c0e829407..4c19abbaf0 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -688,7 +688,8 @@ int designware_eth_probe(struct udevice *dev) int i, clock_nb; priv->clock_count = 0; - clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells"); + clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells", + 0); if (clock_nb > 0) { priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk), GFP_KERNEL); diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c index db7f39cd0b..8713b8e7b7 100644 --- a/drivers/phy/phy-uclass.c +++ b/drivers/phy/phy-uclass.c @@ -179,7 +179,7 @@ int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk) if (!dev_read_prop(dev, "phys", NULL)) return 0; - count = dev_count_phandle_with_args(dev, "phys", "#phy-cells"); + count = dev_count_phandle_with_args(dev, "phys", "#phy-cells", 0); if (count < 1) return count; diff --git a/drivers/power/domain/power-domain-uclass.c b/drivers/power/domain/power-domain-uclass.c index c2c7c3bd50..af829db9da 100644 --- a/drivers/power/domain/power-domain-uclass.c +++ b/drivers/power/domain/power-domain-uclass.c @@ -117,7 +117,7 @@ static int dev_power_domain_ctrl(struct udevice *dev, bool on) int i, count, ret = 0; count = dev_count_phandle_with_args(dev, "power-domains", - "#power-domain-cells"); + "#power-domain-cells", 0); for (i = 0; i < count; i++) { ret = power_domain_get_by_index(dev, &pd, i); if (ret) diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c index 5e38ce5c06..411ad649ca 100644 --- a/drivers/reset/reset-uclass.c +++ b/drivers/reset/reset-uclass.c @@ -106,7 +106,7 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk) bulk->count = 0; - count = dev_count_phandle_with_args(dev, "resets", "#reset-cells"); + count = dev_count_phandle_with_args(dev, "resets", "#reset-cells", 0); if (count < 1) return count; diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c index 304a3437d5..c93a7051a7 100644 --- a/drivers/usb/host/ehci-generic.c +++ b/drivers/usb/host/ehci-generic.c @@ -86,7 +86,7 @@ static int ehci_usb_probe(struct udevice *dev) err = 0; priv->clock_count = 0; clock_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "clocks", - "#clock-cells"); + "#clock-cells", 0); if (clock_nb > 0) { priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk), GFP_KERNEL); @@ -116,7 +116,7 @@ static int ehci_usb_probe(struct udevice *dev) priv->reset_count = 0; reset_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "resets", - "#reset-cells"); + "#reset-cells", 0); if (reset_nb > 0) { priv->resets = devm_kcalloc(dev, reset_nb, sizeof(struct reset_ctl), diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 22e7b565b5..aa1eba262a 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -95,7 +95,8 @@ static int ohci_da8xx_probe(struct udevice *dev) err = 0; priv->clock_count = 0; - clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells"); + clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells", + 0); if (clock_nb < 0) return clock_nb; diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c index b84bf8ac0f..7a286435c6 100644 --- a/drivers/usb/host/ohci-generic.c +++ b/drivers/usb/host/ohci-generic.c @@ -85,7 +85,8 @@ static int ohci_usb_probe(struct udevice *dev) err = 0; priv->clock_count = 0; - clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells"); + clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells", + 0); if (clock_nb > 0) { priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk), GFP_KERNEL); @@ -111,7 +112,8 @@ static int ohci_usb_probe(struct udevice *dev) } priv->reset_count = 0; - reset_nb = dev_count_phandle_with_args(dev, "resets", "#reset-cells"); + reset_nb = dev_count_phandle_with_args(dev, "resets", "#reset-cells", + 0); if (reset_nb > 0) { priv->resets = devm_kcalloc(dev, reset_nb, sizeof(struct reset_ctl), diff --git a/include/dm/of_access.h b/include/dm/of_access.h index 2fa65c9332..cc382b1671 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -450,6 +450,7 @@ int of_parse_phandle_with_args(const struct device_node *np, * @np: pointer to a device tree node containing a list * @list_name: property name that contains a list * @cells_name: property name that specifies phandles' arguments count + * @cells_count: Cell count to use if @cells_name is NULL * @return number of phandle found, -ENOENT if * @list_name does not exist, -EINVAL if a phandle was not found, * @cells_name could not be found, the arguments were truncated or there @@ -460,7 +461,8 @@ int of_parse_phandle_with_args(const struct device_node *np, * */ int of_count_phandle_with_args(const struct device_node *np, - const char *list_name, const char *cells_name); + const char *list_name, const char *cells_name, + int cells_count); /** * of_alias_scan() - Scan all properties of the 'aliases' node diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 8df2facf99..1726b6b2f9 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -555,12 +555,13 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, * @node: device tree node containing a list * @list_name: property name that contains a list * @cells_name: property name that specifies phandles' arguments count + * @cells_count: Cell count to use if @cells_name is NULL * @return number of phandle on success, -ENOENT if @list_name does not * exist, -EINVAL if a phandle was not found, @cells_name could not * be found. */ int ofnode_count_phandle_with_args(ofnode node, const char *list_name, - const char *cells_name); + const char *cells_name, int cell_count); /** * ofnode_path() - find a node by full path diff --git a/include/dm/read.h b/include/dm/read.h index 67db94adfc..0585eb1228 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -429,12 +429,14 @@ int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, * @dev: device whose node containing a list * @list_name: property name that contains a list * @cells_name: property name that specifies phandles' arguments count + * @cells_count: Cell count to use if @cells_name is NULL * @Returns number of phandle found on success, on error returns appropriate * errno value. */ int dev_count_phandle_with_args(const struct udevice *dev, - const char *list_name, const char *cells_name); + const char *list_name, const char *cells_name, + int cell_count); /** * dev_read_addr_cells() - Get the number of address cells for a device's node @@ -880,10 +882,10 @@ static inline int dev_read_phandle_with_args(const struct udevice *dev, } static inline int dev_count_phandle_with_args(const struct udevice *dev, - const char *list_name, const char *cells_name) + const char *list_name, const char *cells_name, int cell_count) { return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, - cells_name); + cells_name, cell_count); } static inline int dev_read_addr_cells(const struct udevice *dev) From patchwork Fri Sep 25 07:41:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1371085 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=O9UoHwND; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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) by ozlabs.org (Postfix) with ESMTPS id 4ByP4P3NN3z9sSf for ; Fri, 25 Sep 2020 17:41:41 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 248F0824F9; Fri, 25 Sep 2020 09:41:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.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=st.com header.i=@st.com header.b="O9UoHwND"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C430D824FB; Fri, 25 Sep 2020 09:41:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 34D7A82423 for ; Fri, 25 Sep 2020 09:41:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08P7bn76018153; Fri, 25 Sep 2020 09:41:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=cHqeQ3iWUV+/wErWkTrkCFE3cwr30HVGPkjBlkFT+JM=; b=O9UoHwNDq3xFypFo6FGADuwKS7JkT8VGLCgV5h8DmFmEKT0XaOxb1cnjHkUdmB56tnsh onmLwJHsrpFq8sbdEB4MqVfzDpWPzLixj3hMmXpXE71xjyPiRqNMzfuRcPYCXTSsAuwO 9tqVk74xk8gts8A4Q7m+Gz4ec71CsKtg8ni5JxCPvdEbmolv5UfbVqSJxbMNFeZQ0783 zduOqKevV5PCxA9Z3Punx3bWVuXOWCgmk0pMX6qiFUrsbNYwADmGgdnmOylpPH0wV7Y9 nmQJ8fXw7KXdKaq0qqcb6Z1FkNMBq8zvQipudun9xvyHUeIUP7szcyJOIKqoXyEtOWBW /A== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 33n748k6t1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 09:41:29 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8FD86100034; Fri, 25 Sep 2020 09:41:28 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 82C9221FE8F; Fri, 25 Sep 2020 09:41:28 +0200 (CEST) Received: from localhost (10.75.127.47) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 25 Sep 2020 09:41:28 +0200 From: Patrick Delaunay To: CC: Patrick Delaunay , Simon Glass , U-Boot STM32 Subject: [PATCH 2/3] fdtdec: correct test on return of fdt_node_offset_by_phandle Date: Fri, 25 Sep 2020 09:41:15 +0200 Message-ID: <20200925074116.16068-2-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925074116.16068-1-patrick.delaunay@st.com> References: <20200925074116.16068-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG8NODE2.st.com (10.75.127.23) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-25_02:2020-09-24, 2020-09-25 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean The result of fdt_node_offset_by_phandle is negative for error, so this patch corrects the check of this result in fdtdec_parse_phandle_with_args. This patch allows to have the same behavior with or without OF_LIVE for the function dev_read_phandle_with_args with cell_name = NULL and with invalid phandle. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass Reviewed-by: Simon Glass --- lib/fdtdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index d3b22ec323..90d7e50646 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -746,7 +746,7 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node, if (cells_name || cur_index == index) { node = fdt_node_offset_by_phandle(blob, phandle); - if (!node) { + if (node < 0) { debug("%s: could not find phandle\n", fdt_get_name(blob, src_node, NULL)); From patchwork Fri Sep 25 07:41:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1371086 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=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=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=IxiUSbfu; 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4ByP4Z2VWFz9sS8 for ; Fri, 25 Sep 2020 17:41:50 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C87FD8250B; Fri, 25 Sep 2020 09:41:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.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=st.com header.i=@st.com header.b="IxiUSbfu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8D42A8250F; Fri, 25 Sep 2020 09:41:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8CF9C824FE for ; Fri, 25 Sep 2020 09:41:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08P7bn77018153; Fri, 25 Sep 2020 09:41:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=L159NDEmrpaUnt8x8KCAzlenWPUEbC75fXKoC0g8nP4=; b=IxiUSbfuLvG4qUxQQhtK4UZQxlscK0zygXMCvb5Woe7UwV3zhdz7cMX9l1lHzuPbDCl8 3ShBC/2UiKKjIM7eICC7+sO5tm0jPdRN4Qt56Jbir/hQYLmad5c09N7pW72dV29peXcu idddM3R95nz0FEItxiqPjSU31AbRWI4oLw8Q8YTiGADE8hpIPtN+qvD7IZ0u0RQs2dQj WWmnUBZqXN/YaV6DljCaB2fxgogMZKDm13vjZT4SMqwAxtRSeMCqzgHp0FSk5aFb/wyr YAccg6E0JcDX7nb0tJ9q8nHhbkjAuxsvg/YB1iAnarzglZWbmf4FIlduQNbPGS2b31ln YA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 33n748k6t4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 09:41:30 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A3A5110002A; Fri, 25 Sep 2020 09:41:29 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 6B31E21FE8A; Fri, 25 Sep 2020 09:41:29 +0200 (CEST) Received: from localhost (10.75.127.46) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 25 Sep 2020 09:41:28 +0200 From: Patrick Delaunay To: CC: Patrick Delaunay , AKASHI Takahiro , Bin Meng , Chunfeng Yun , Heiko Schocher , Philippe Reynes , Sean Anderson , Simon Glass , Wolfgang Wallner , U-Boot STM32 Subject: [PATCH 3/3] test: dm: add test for phandle access functions Date: Fri, 25 Sep 2020 09:41:16 +0200 Message-ID: <20200925074116.16068-3-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925074116.16068-1-patrick.delaunay@st.com> References: <20200925074116.16068-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG1NODE1.st.com (10.75.127.1) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-25_02:2020-09-24, 2020-09-25 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add unitary test for phandle access functions - ofnode_count_phandle_with_args - ofnode_parse_phandle_with_args - dev_count_phandle_with_args - dev_read_phandle_with_args Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass Reviewed-by: Simon Glass --- arch/sandbox/dts/test.dts | 1 + test/dm/ofnode.c | 75 +++++++++++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 9f45c48e4e..25d4b2e598 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -128,6 +128,7 @@ str-value = "test string"; interrupts-extended = <&irq 3 0>; acpi,name = "GHIJ"; + phandle-value = <&gpio_c 10>, <0xFFFFFFFF 20>, <&gpio_a 30>; }; junk { diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 8bfb706602..84c49c4f18 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -87,6 +87,81 @@ static int dm_test_ofnode_read(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); +static int dm_test_ofnode_phandle(struct unit_test_state *uts) +{ + struct ofnode_phandle_args args; + ofnode node; + int ret; + const char prop[] = "test-gpios"; + const char cell[] = "#gpio-cells"; + const char prop2[] = "phandle-value"; + + node = ofnode_path("/a-test"); + ut_assert(ofnode_valid(node)); + + /* Test ofnode_count_phandle_with_args with cell name */ + ret = ofnode_count_phandle_with_args(node, "missing", cell, 0); + ut_asserteq(-ENOENT, ret); + ret = ofnode_count_phandle_with_args(node, prop, "#invalid", 0); + ut_asserteq(-EINVAL, ret); + ret = ofnode_count_phandle_with_args(node, prop, cell, 0); + ut_asserteq(5, ret); + + /* Test ofnode_parse_phandle_with_args with cell name */ + ret = ofnode_parse_phandle_with_args(node, "missing", cell, 0, 0, + &args); + ut_asserteq(-ENOENT, ret); + ret = ofnode_parse_phandle_with_args(node, prop, "#invalid", 0, 0, + &args); + ut_asserteq(-EINVAL, ret); + ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 0, &args); + ut_assertok(ret); + ut_asserteq(1, args.args_count); + ut_asserteq(1, args.args[0]); + ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 1, &args); + ut_assertok(ret); + ut_asserteq(1, args.args_count); + ut_asserteq(4, args.args[0]); + ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 2, &args); + ut_assertok(ret); + ut_asserteq(5, args.args_count); + ut_asserteq(5, args.args[0]); + ut_asserteq(1, args.args[4]); + ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 3, &args); + ut_asserteq(-ENOENT, ret); + ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 4, &args); + ut_assertok(ret); + ut_asserteq(1, args.args_count); + ut_asserteq(12, args.args[0]); + ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 5, &args); + ut_asserteq(-ENOENT, ret); + + /* Test ofnode_count_phandle_with_args with cell count */ + ret = ofnode_count_phandle_with_args(node, "missing", NULL, 2); + ut_asserteq(-ENOENT, ret); + ret = ofnode_count_phandle_with_args(node, prop2, NULL, 1); + ut_asserteq(3, ret); + + /* Test ofnode_parse_phandle_with_args with cell count */ + ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 0, &args); + ut_assertok(ret); + ut_asserteq(1, ofnode_valid(args.node)); + ut_asserteq(1, args.args_count); + ut_asserteq(10, args.args[0]); + ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 1, &args); + ut_asserteq(-EINVAL, ret); + ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 2, &args); + ut_assertok(ret); + ut_asserteq(1, ofnode_valid(args.node)); + ut_asserteq(1, args.args_count); + ut_asserteq(30, args.args[0]); + ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 3, &args); + ut_asserteq(-ENOENT, ret); + + return 0; +} +DM_TEST(dm_test_ofnode_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) { const char *str; diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 04802deb7f..862b7ce8b1 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -968,6 +968,71 @@ static int dm_test_read_int_index(struct unit_test_state *uts) } DM_TEST(dm_test_read_int_index, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); +static int dm_test_read_phandle(struct unit_test_state *uts) +{ + struct udevice *dev; + struct ofnode_phandle_args args; + int ret; + const char prop[] = "test-gpios"; + const char cell[] = "#gpio-cells"; + const char prop2[] = "phandle-value"; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); + ut_asserteq_str("a-test", dev->name); + + /* Test dev_count_phandle_with_args with cell name */ + ret = dev_count_phandle_with_args(dev, "missing", cell, 0); + ut_asserteq(-ENOENT, ret); + ret = dev_count_phandle_with_args(dev, prop, "#invalid", 0); + ut_asserteq(-EINVAL, ret); + ut_asserteq(5, dev_count_phandle_with_args(dev, prop, cell, 0)); + + /* Test dev_read_phandle_with_args with cell name */ + ret = dev_read_phandle_with_args(dev, "missing", cell, 0, 0, &args); + ut_asserteq(-ENOENT, ret); + ret = dev_read_phandle_with_args(dev, prop, "#invalid", 0, 0, &args); + ut_asserteq(-EINVAL, ret); + ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 0, &args)); + ut_asserteq(1, args.args_count); + ut_asserteq(1, args.args[0]); + ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 1, &args)); + ut_asserteq(1, args.args_count); + ut_asserteq(4, args.args[0]); + ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 2, &args)); + ut_asserteq(5, args.args_count); + ut_asserteq(5, args.args[0]); + ut_asserteq(1, args.args[4]); + ret = dev_read_phandle_with_args(dev, prop, cell, 0, 3, &args); + ut_asserteq(-ENOENT, ret); + ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 4, &args)); + ut_asserteq(1, args.args_count); + ut_asserteq(12, args.args[0]); + ret = dev_read_phandle_with_args(dev, prop, cell, 0, 5, &args); + ut_asserteq(-ENOENT, ret); + + /* Test dev_count_phandle_with_args with cell count */ + ret = dev_count_phandle_with_args(dev, "missing", NULL, 2); + ut_asserteq(-ENOENT, ret); + ut_asserteq(3, dev_count_phandle_with_args(dev, prop2, NULL, 1)); + + /* Test dev_read_phandle_with_args with cell count */ + ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 0, &args)); + ut_asserteq(1, ofnode_valid(args.node)); + ut_asserteq(1, args.args_count); + ut_asserteq(10, args.args[0]); + ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 1, &args); + ut_asserteq(-EINVAL, ret); + ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 2, &args)); + ut_asserteq(1, ofnode_valid(args.node)); + ut_asserteq(1, args.args_count); + ut_asserteq(30, args.args[0]); + ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 3, &args); + ut_asserteq(-ENOENT, ret); + + return 0; +} +DM_TEST(dm_test_read_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + /* Test iteration through devices by drvdata */ static int dm_test_uclass_drvdata(struct unit_test_state *uts) {