diff mbox series

[U-Boot,1/1] atcspi200: avoid possible NULL dereference

Message ID 20180131000554.7465-1-xypron.glpk@gmx.de
State Accepted
Commit 923837e159c5886be38c7a83a2d6bc489b35c1f4
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/1] atcspi200: avoid possible NULL dereference | expand

Commit Message

Heinrich Schuchardt Jan. 31, 2018, 12:05 a.m. UTC
Check if ns before and not after dereferencing it.

Indicated by cppcheck.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 drivers/spi/atcspi200_spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Tom Rini Feb. 8, 2018, 12:27 p.m. UTC | #1
On Wed, Jan 31, 2018 at 01:05:54AM +0100, Heinrich Schuchardt wrote:

> Check if ns before and not after dereferencing it.
> 
> Indicated by cppcheck.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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