summaryrefslogtreecommitdiff
path: root/drivers/spi/atcspi200_spi.c
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-01-31 01:05:54 +0100
committerTom Rini <trini@konsulko.com>2018-02-07 22:06:18 -0500
commit923837e159c5886be38c7a83a2d6bc489b35c1f4 (patch)
tree60b8e0917f38e3036453fda717d8bb4e4d048e4c /drivers/spi/atcspi200_spi.c
parent8639e34d2c5e12cc2e45c95b1a2e97c22bf6a711 (diff)
atcspi200: avoid possible NULL dereference
Check if ns before and not after dereferencing it. Indicated by cppcheck. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'drivers/spi/atcspi200_spi.c')
-rw-r--r--drivers/spi/atcspi200_spi.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/spi/atcspi200_spi.c b/drivers/spi/atcspi200_spi.c
index 3e29df03a4..5b2e9d6264 100644
--- a/drivers/spi/atcspi200_spi.c
+++ b/drivers/spi/atcspi200_spi.c
@@ -297,6 +297,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
return NULL;
ns = spi_alloc_slave(struct nds_spi_slave, bus, cs);
+ if (!ns)
+ return NULL;
switch (bus) {
case SPI0_BUS:
@@ -316,8 +318,6 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
ns->to = SPI_TIMEOUT;
ns->max_transfer_length = MAX_TRANSFER_LEN;
ns->slave.max_write_size = MAX_TRANSFER_LEN;
- if (!ns)
- return NULL;
return &ns->slave;
}