Skip to contentSkip to conversation

atcspi200: avoid possible NULL dereference

PATCH New Heinrich Schuchardt 2 participants 2 messages Jan 31, 2018 – Feb 8, 2018 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 atcspi200: avoid possible NULL dereference

Check if ns before and not after dereferencing it.

Indicated by cppcheck.

---
 drivers/spi/atcspi200_spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/atcspi200_spi.c +2 -2
index 3e29df03a4..5b2e9d6264 100644
@@ -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;
 }
Signature · 1 line
2.15.1
#1 lore raw

PATCH 1/1 atcspi200: avoid possible NULL dereference

Quoted 5 lines · Heinrich Schuchardt

Check if ns before and not after dereferencing it.

Indicated by cppcheck.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180208/286e7fe5/attachment.sig>