]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
spi: Add missing error handling for CS GPIOs
authorGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 24 May 2019 06:48:00 +0000 (08:48 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 2 Jul 2019 10:07:53 +0000 (12:07 +0200)
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@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 1723fdec5fcbc4de3d26bbb23a9e1704ee258955)
Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Acked-by: Khalid Elmously <khalid.elmously@canonical.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/spi/spi.c

index 0e0f2c62973c0ca2ed5d05d591994143ae6d92b9..41f3e389c0acca3c0ce699933320f8f0aa275a8b 100644 (file)
@@ -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]) {
                        /*