aboutsummaryrefslogtreecommitdiff
path: root/drivers/spi/soft_spi.c
diff options
context:
space:
mode:
authorChristophe Kerello2019-08-02 15:46:29 +0200
committerJagan Teki2019-09-16 08:09:22 +0530
commitdfe72d081d4eda0c0788dc5db69de3abbec1b857 (patch)
tree0b73466d5be7db114ce20dc51dccfc7c1020b84b /drivers/spi/soft_spi.c
parent07a5cb9d3b9bf9bca9ca207b82f92eac73cbdda8 (diff)
spi: soft_spi: Fix data abort if slave is not probed
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>
Diffstat (limited to 'drivers/spi/soft_spi.c')
-rw-r--r--drivers/spi/soft_spi.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c
index b06883f9d04..b80f810bd15 100644
--- a/drivers/spi/soft_spi.c
+++ b/drivers/spi/soft_spi.c
@@ -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) ||