]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
spi: soft_spi: Fix data abort if slave is not probed
authorChristophe Kerello <christophe.kerello@st.com>
Fri, 2 Aug 2019 13:46:29 +0000 (15:46 +0200)
committerJagan Teki <jagan@amarulasolutions.com>
Mon, 16 Sep 2019 02:39:22 +0000 (08:09 +0530)
In case spi_get_bus_and_cs callback is used, spi bus is first probed
then slave devices are probed. To avoid a data abort in soft_spi probe
function, we need to check that (slave != NULL).

If slave is NULL, cs_flags and clk_flags will be initialized with
respectively GPIOD_ACTIVE_LOW and 0.

Signed-off-by: Christophe Kerello <christophe.kerello@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
drivers/spi/soft_spi.c

index b06883f9d0448bd026bee20eadcb4e54a10f5a3f..b80f810bd157ae464bd39a94f0d9bdab6f66b86b 100644 (file)
@@ -215,8 +215,8 @@ static int soft_spi_probe(struct udevice *dev)
        int cs_flags, clk_flags;
        int ret;
 
-       cs_flags = (slave->mode & SPI_CS_HIGH) ? 0 : GPIOD_ACTIVE_LOW;
-       clk_flags = (slave->mode & SPI_CPOL) ? GPIOD_ACTIVE_LOW : 0;
+       cs_flags = (slave && slave->mode & SPI_CS_HIGH) ? 0 : GPIOD_ACTIVE_LOW;
+       clk_flags = (slave && slave->mode & SPI_CPOL) ? GPIOD_ACTIVE_LOW : 0;
 
        if (gpio_request_by_name(dev, "cs-gpios", 0, &plat->cs,
                                 GPIOD_IS_OUT | cs_flags) ||