Skip to contentSkip to conversation

spi: atmel: check GPIO validity before using cs_gpios

PATCH New Wenyou Yang 2 participants 2 messages Apr 7, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 spi: atmel: check GPIO validity before using cs_gpios

Before using the cs_gpio, check if the GPIO is valid or not.

---

Changes in v3:
- According to the advice from Jagan Teki, rearrange the code.

Changes in v2:
- Rebase on v2017.03.

 drivers/spi/atmel_spi.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/spi/atmel_spi.c +9 -0
index 7649114231..4701b79f16 100644
@@ -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);
 	}
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/1 spi: atmel: check GPIO validity before using cs_gpios

Quoted 3 lines · Wenyou Yang

Before using the cs_gpio, check if the GPIO is valid or not.

--

Applied to u-boot-spi/master

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.