From: Simon Glass <sjg@chromium.org>
Date: Thu, 1 Jun 2023 16:22:30 +0000 (-0600)
Subject: gpio: Avoid using an invalid ofnode
X-Git-Tag: v2025.01-rc5-pxa1908~943^2~34
X-Git-Url: http://git.dujemihanovic.xyz/html/static/%7B%7B%20%24.Site.BaseURL%20%7D%7Dposts/%7B%7B%20%24.Site.BaseURL%20%7D%7Dposts/index.xml?a=commitdiff_plain;h=11c341b118a236423a294a7d62f71bf33e20aea3;p=u-boot.git

gpio: Avoid using an invalid ofnode

Devices do not necessarily have nodes attached to them, since they can be
created from platdata. In SPL a devicetree may in fact not exist at all.

Check the node before using it. This avoids failure when OF_CHECKS is
enabled.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 5fc7cf8c8e2 ("gpio: add gpio-hog support")
Reviewed-by: Heiko Schocher <hs@denx.de>
---

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 712119c341..31027f3d99 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -1474,7 +1474,7 @@ static int gpio_post_bind(struct udevice *dev)
 	}
 #endif
 
-	if (CONFIG_IS_ENABLED(GPIO_HOG)) {
+	if (CONFIG_IS_ENABLED(GPIO_HOG) && dev_has_ofnode(dev)) {
 		struct udevice *child;
 		ofnode node;