Skip to contentSkip to conversation

mtd: spi: check return value of spi_setup_slave

PATCH New Peng Fan 2 participants 2 messages Mar 20, 2015 – Apr 22, 2015 Memory technology devices (MTD)

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH 1/1 mtd: spi: check return value of spi_setup_slave

Need to check value of spi_setup_slave and spi_setup_slave_fdt. If their return value 'bus' is NULL, there is no need to pass it to following spi_flash_probe_tail.

If 'bus' is null, the original function flow is as following:
spi_flash_probe

	|->spi_setup_slave
	|->spi_probe_bus_tail
		|->spi_flash_probe_slave
		|->spi_free_slave

Alougth check the pointer in spi_free_slave is ok, checking the return value of spi_setup_slave and spi_setup_slave_fdt is better.

Before this fix:
"
=> sf probe 0:2
FSL_QSPI: Not a valid cs !
SF: Failed to set up slave
data abort

pc : [<fff66dcc>]          lr : [<fff7628c>]

reloc pc : [<87814dcc>] lr : [<8782428c>]
sp : fdf4fcf0 ip : e630396c fp : fe0d0888
r10: fffa2538 r9 : fdf4feb8 r8 : 02625a00
r7 : 00000002 r6 : fff94ec0 r5 : 00000000 r4 : 9355553c
r3 : 1af0593c r2 : cb3fe030 r1 : fff94eb8 r0 : e59ff018
Flags: nZCv IRQs off FIQs off Mode SVC_32
Resetting CPU ...
"

After this fix:
"
=> sf probe 0:2
FSL_QSPI: Not a valid cs !
Failed to initialize SPI flash at 0:2
"
No data abort using this patch.

---
 drivers/mtd/spi/sf_probe.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi/sf_probe.c +4 -0
index 4103723..689af3a 100644
@@ -433,6 +433,8 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs,
 	struct spi_slave *bus;
 
 	bus = spi_setup_slave(busnum, cs, max_hz, spi_mode);
+	if (!bus)
+		return NULL;
 	return spi_flash_probe_tail(bus);
 }
 
@@ -443,6 +445,8 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
 	struct spi_slave *bus;
 
 	bus = spi_setup_slave_fdt(blob, slave_node, spi_node);
+	if (!bus)
+		return NULL;
 	return spi_flash_probe_tail(bus);
 }
 #endif
Signature · 1 line
1.8.4
#1 lore raw

PATCH 1/1 mtd: spi: check return value of spi_setup_slave

Quoted 65 lines · Peng Fan

Need to check value of spi_setup_slave and spi_setup_slave_fdt. If their return value 'bus' is NULL, there is no need to pass it to following spi_flash_probe_tail.

If 'bus' is null, the original function flow is as following:
spi_flash_probe

        |->spi_setup_slave
        |->spi_probe_bus_tail
                |->spi_flash_probe_slave
                |->spi_free_slave

Alougth check the pointer in spi_free_slave is ok, checking the return value of spi_setup_slave and spi_setup_slave_fdt is better.

Before this fix:
"
=> sf probe 0:2
FSL_QSPI: Not a valid cs !
SF: Failed to set up slave
data abort

pc : [<fff66dcc>]          lr : [<fff7628c>]

reloc pc : [<87814dcc>] lr : [<8782428c>]
sp : fdf4fcf0 ip : e630396c fp : fe0d0888
r10: fffa2538 r9 : fdf4feb8 r8 : 02625a00
r7 : 00000002 r6 : fff94ec0 r5 : 00000000 r4 : 9355553c
r3 : 1af0593c r2 : cb3fe030 r1 : fff94eb8 r0 : e59ff018
Flags: nZCv IRQs off FIQs off Mode SVC_32
Resetting CPU ...
"

After this fix:
"
=> sf probe 0:2
FSL_QSPI: Not a valid cs !
Failed to initialize SPI flash at 0:2
"
No data abort using this patch.

---
 drivers/mtd/spi/sf_probe.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi/sf_probe.c +4 -1
index 4103723..689af3a 100644
@@ -433,6 +433,8 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs,
        struct spi_slave *bus;
 
        bus = spi_setup_slave(busnum, cs, max_hz, spi_mode);
+       if (!bus)
+               return NULL;
        return spi_flash_probe_tail(bus);
 }
 
@@ -443,6 +445,8 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
        struct spi_slave *bus;
 
        bus = spi_setup_slave_fdt(blob, slave_node, spi_node);
+       if (!bus)
+               return NULL;
        return spi_flash_probe_tail(bus);
 }
 #endif
--
Quoted 3 lines

1.8.4

Applied to u-boot-spi/master

thanks!

Signature · 1 line
Jagan.