From: Marek Vasut Date: Mon, 26 Sep 2016 12:14:53 +0000 (+0200) Subject: spi: imx: Gracefully handle NULL master->cs_gpios X-Git-Tag: Ubuntu-4.9.0-1.2~769^2~3^3~1 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=f13d4e189d209af0f552e9900acd06ee4a35e601;p=mirror_ubuntu-zesty-kernel.git spi: imx: Gracefully handle NULL master->cs_gpios It is possible that master->cs_gpios is NULL after spi_bitbang_start(), this happens if the master has no CS GPIOs specified in DT. Check for this case after spi_bitbang_start() to prevent NULL pointer dereference in the subsequent for loop, which accesses the master->cs_gpios field. Signed-off-by: Marek Vasut Cc: Martin Kaiser Cc: Mark Brown Signed-off-by: Mark Brown --- diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 53e7a326c213..1ef5429afcb6 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -1268,6 +1268,11 @@ static int spi_imx_probe(struct platform_device *pdev) goto out_clk_put; } + if (!master->cs_gpios) { + dev_err(&pdev->dev, "No CS GPIOs available\n"); + goto out_clk_put; + } + for (i = 0; i < master->num_chipselect; i++) { if (!gpio_is_valid(master->cs_gpios[i])) continue;