spi: atmel: check GPIO validity before using cs_gpios
authorWenyou Yang <wenyou.yang@atmel.com>
Fri, 7 Apr 2017 07:14:46 +0000 (15:14 +0800)
committerJagan Teki <jagan@openedev.com>
Wed, 3 May 2017 05:28:54 +0000 (10:58 +0530)
Before using the cs_gpio, check if the GPIO is valid or not.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>
drivers/spi/atmel_spi.c

index 76491142318342da1c7cf222fac7fe531230c5a4..4701b79f161f46b38c1cd39c4580e91248e08740 100644 (file)
@@ -296,6 +296,9 @@ static void atmel_spi_cs_activate(struct udevice *dev)
        struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
        u32 cs = slave_plat->cs;
 
+       if (!dm_gpio_is_valid(&priv->cs_gpios[cs]))
+               return;
+
        dm_gpio_set_value(&priv->cs_gpios[cs], 0);
 }
 
@@ -306,6 +309,9 @@ static void atmel_spi_cs_deactivate(struct udevice *dev)
        struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
        u32 cs = slave_plat->cs;
 
+       if (!dm_gpio_is_valid(&priv->cs_gpios[cs]))
+               return;
+
        dm_gpio_set_value(&priv->cs_gpios[cs], 1);
 }
 
@@ -473,6 +479,9 @@ static int atmel_spi_probe(struct udevice *bus)
        }
 
        for(i = 0; i < ARRAY_SIZE(priv->cs_gpios); i++) {
+               if (!dm_gpio_is_valid(&priv->cs_gpios[i]))
+                       continue;
+
                dm_gpio_set_dir_flags(&priv->cs_gpios[i],
                                      GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
        }