[PATCH 7/7] spi: Add missing error handling for CS GPIOs

Ike Panhc ike.pan at canonical.com
Fri May 24 06:48:29 UTC 2019


From: Geert Uytterhoeven <geert+renesas at glider.be>

BugLink: https://bugs.launchpad.net/bugs/1826142

While devm_gpiod_get_index_optional() returns NULL if the GPIO is not
present (i.e. -ENOENT), it may still return other error codes, like
-EPROBE_DEFER.  Currently these are not handled, leading to
unrecoverable failures later in case of probe deferral:

    gpiod_set_consumer_name: invalid GPIO (errorpointer)
    gpiod_direction_output: invalid GPIO (errorpointer)
    gpiod_set_value_cansleep: invalid GPIO (errorpointer)
    gpiod_set_value_cansleep: invalid GPIO (errorpointer)
    gpiod_set_value_cansleep: invalid GPIO (errorpointer)

Detect and propagate errors to fix this.

Fixes: f3186dd876697e69 ("spi: Optionally use GPIO descriptors for CS GPIOs")
Signed-off-by: Geert Uytterhoeven <geert+renesas at glider.be>
Signed-off-by: Mark Brown <broonie at kernel.org>
(cherry picked from commit 1723fdec5fcbc4de3d26bbb23a9e1704ee258955)
Signed-off-by: Ike Panhc <ike.pan at canonical.com>
---
 drivers/spi/spi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 0e0f2c62973c..41f3e389c0ac 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2194,6 +2194,8 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr)
 		 */
 		cs[i] = devm_gpiod_get_index_optional(dev, "cs", i,
 						      GPIOD_OUT_LOW);
+		if (IS_ERR(cs[i]))
+			return PTR_ERR(cs[i]);
 
 		if (cs[i]) {
 			/*
-- 
2.17.1




More information about the kernel-team mailing list