UPSTREAM: atcspi200: avoid possible NULL dereference

Check if ns before and not after dereferencing it.

Indicated by cppcheck.

Change-Id: Ic9a2491051754fef64ce7ad4a9a5377fc3aad6db
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
(cherry picked from commit 923837e159c5886be38c7a83a2d6bc489b35c1f4)
This commit is contained in:
Heinrich Schuchardt 2018-01-31 01:05:54 +01:00 committed by Kever Yang
parent ccb5fa0a6b
commit 70716f3196
1 changed files with 2 additions and 2 deletions

View File

@ -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;
}