diff mbox series

[v4,1/5] dm: gpio: Fix gpio_get_list_count failing with livetree

Message ID 20210420145058.3934010-2-sean.anderson@seco.com
State Accepted
Commit 430e136dc1398546ad2b1db08692e9edac480cc8
Delegated to: Tom Rini
Headers show
Series sysinfo: Add gpio sysinfo driver | expand

Commit Message

Sean Anderson April 20, 2021, 2:50 p.m. UTC
of_parse_phandle_with_args (called by dev_read_phandle_with_args) does not
support getting the length of a phandle list by using the index -1.
Instead, use dev_count_phandle_with_args which supports exactly this
use-case.

Fixes: 8558217153 ("gpio: Convert to use APIs which support live DT")

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

(no changes since v3)

Changes in v3:
- Fix assuming any nonzero return of dev_count_phandle_with_args was an error.

Changes in v2:
- Change Fixes tag to the most recent commit touching these lines

 drivers/gpio/gpio-uclass.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Tom Rini May 6, 2021, 3:02 p.m. UTC | #1
On Tue, Apr 20, 2021 at 10:50:54AM -0400, Sean Anderson wrote:

> of_parse_phandle_with_args (called by dev_read_phandle_with_args) does not
> support getting the length of a phandle list by using the index -1.
> Instead, use dev_count_phandle_with_args which supports exactly this
> use-case.
> 
> Fixes: 8558217153 ("gpio: Convert to use APIs which support live DT")
> 
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index e4e7f58c39..131099cc17 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -1215,9 +1215,9 @@  int gpio_get_list_count(struct udevice *dev, const char *list_name)
 {
 	int ret;
 
-	ret = dev_read_phandle_with_args(dev, list_name, "#gpio-cells", 0, -1,
-					 NULL);
-	if (ret) {
+	ret = dev_count_phandle_with_args(dev, list_name, "#gpio-cells",
+					  -ENOENT);
+	if (ret < 0) {
 		debug("%s: Node '%s', property '%s', GPIO count failed: %d\n",
 		      __func__, dev->name, list_name, ret);
 	}