[PATCH v3 6/6] gpio: delay: free already-requested GPIOs on probe failure

Pranav Sanwal <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
gpio_delay_probe() requests each wrapped real GPIO in a loop and
returns immediately if gpio_request_by_name_nodev() fails partway
through, without freeing the GPIOs it already successfully requested.
gpio_delay_remove() does not cover this either, since .remove is only
called for devices that finished probing.

Free what was already requested via the same gpio_delay_free_wrapped()
helper gpio_delay_remove() uses, bounded by the number of GPIOs
actually requested so far rather than the full gpio_count.

Fixes: c866f2f197e2 ("gpio: Add GPIO delay driver")
Suggested-by: Simon Glass <[email protected]>
Signed-off-by: Pranav Sanwal <[email protected]>
---
 drivers/gpio/gpio-delay.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-delay.c b/drivers/gpio/gpio-delay.c
index 27fc59b5ee4..747c520fb46 100644
--- a/drivers/gpio/gpio-delay.c
+++ b/drivers/gpio/gpio-delay.c
@@ -150,8 +150,10 @@ static int gpio_delay_probe(struct udevice *dev)
 		d = &priv->descs[i];
 		ret = gpio_request_by_name_nodev(node, "gpios", i,
 						 &d->real_gpio, 0);
-		if (ret)
+		if (ret) {
+			gpio_delay_free_wrapped(dev, i);
 			return ret;
+		}
 	}
 
 	return 0;
-- 
2.43.7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.