Skip to contentSkip to conversation

spi-nor: fix spi_nor_probe

PATCH In review Pascal Fabreges 2 participants 2 messages Apr 25, 2022 – Apr 29, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi-nor: fix spi_nor_probe

In rare cases, 7 on 5000 power off/on, the spi-nor driver is probed too soon.
The controller is not in "running" mode.

The spi-nor driver take the hand before the end of the spi_start_queue procedure which set the running mode to true after the spi_init_queue (Initialize and start queue).

kernel: spi_master spi0: spi_init_queue: ctlr->running = false
kernel: device: 'spi0.1': device_add
kernel: bus: 'spi': add device spi0.1
kernel: bus: 'spi': driver_probe_device: matched device spi0.1 with driver spi-nor
kernel: bus: 'spi': really_probe: probing driver spi-nor with device spi0.1
kernel: spi-nor spi0.1: no pinctrl handle
kernel: spi-nor spi0.1: spi_nor_probe: Caller name: really_probe+0x2b3/0x3e0
kernel: spi-nor spi0.1: spi_nor_probe: Call spi_nor_scan
kernel: spi_master spi0: spi_mem_exec_op: Caller name: spi_nor_read_id+0x89/0x190
kernel: spi-nor spi0.1: spi_sync: Caller name: spi_mem_exec_op+0x2f5/0x460
kernel: spi-nor spi0.1: __spi_sync: call __spi_queued_transfer
kernel: spi-nor spi0.1: __spi_queued_transfer: return -ESHUTDOWN
kernel: spi-nor spi0.1: error -108 reading JEDEC ID 00 00 00 00 00 00
kernel: spi-nor: probe of spi0.1 failed with error -108

---
 drivers/mtd/spi-nor/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mtd/spi-nor/core.c +3 -0
index e6b8b19a68ee..dd82f42c29db 100644
@@ -3618,6 +3618,9 @@ static int spi_nor_probe(struct spi_mem *spimem)
 	char *flash_name;
 	int ret;
 
+	if (!spi->controller->running)
+		return -EPROBE_DEFER;
+
 	nor = devm_kzalloc(&spi->dev, sizeof(*nor), GFP_KERNEL);
 	if (!nor)
 		return -ENOMEM;
Signature · 6 lines
2.32.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

Hi Pascal,

Thanks for the patch.

Please use the prefix "mtd: spi-nor: core: " for your patch subject. You can run git log on a particular file or subsystem to see what prefixes they use.

Also please send the patch to _all_ maintainers for the subsystem using scripts/get_maintainer.pl.

Anyway, see my review below.

Quoted 33 lines · Pascal Fabreges

In rare cases, 7 on 5000 power off/on, the spi-nor driver is probed too soon.
The controller is not in "running" mode.

The spi-nor driver take the hand before the end of the spi_start_queue procedure which set the running mode to true after the spi_init_queue (Initialize and start queue).

kernel: spi_master spi0: spi_init_queue: ctlr->running = false
kernel: device: 'spi0.1': device_add
kernel: bus: 'spi': add device spi0.1
kernel: bus: 'spi': driver_probe_device: matched device spi0.1 with driver spi-nor
kernel: bus: 'spi': really_probe: probing driver spi-nor with device spi0.1
kernel: spi-nor spi0.1: no pinctrl handle
kernel: spi-nor spi0.1: spi_nor_probe: Caller name: really_probe+0x2b3/0x3e0
kernel: spi-nor spi0.1: spi_nor_probe: Call spi_nor_scan
kernel: spi_master spi0: spi_mem_exec_op: Caller name: spi_nor_read_id+0x89/0x190
kernel: spi-nor spi0.1: spi_sync: Caller name: spi_mem_exec_op+0x2f5/0x460
kernel: spi-nor spi0.1: __spi_sync: call __spi_queued_transfer
kernel: spi-nor spi0.1: __spi_queued_transfer: return -ESHUTDOWN
kernel: spi-nor spi0.1: error -108 reading JEDEC ID 00 00 00 00 00 00
kernel: spi-nor: probe of spi0.1 failed with error -108

---
 drivers/mtd/spi-nor/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mtd/spi-nor/core.c +0 -0
index e6b8b19a68ee..dd82f42c29db 100644

drivers/mtd/spi-nor/core.c static int spi_nor_probe(struct spi_mem *spimem) · line 3623

Quoted 6 lines
drivers/mtd/spi-nor/core.c +3 -0
@@ -3618,6 +3618,9 @@ static int spi_nor_probe(struct spi_mem *spimem)
 	char *flash_name;
 	int ret;
 
+	if (!spi->controller->running)
+		return -EPROBE_DEFER;
+

This is not the correct place to do this. SPI or SPI MEM should be checking this, and they should not call the peripheral (SPI NOR, SPI NAND, etc.) probe at all unless the controller is ready.

Quoted 3 lines
drivers/mtd/spi-nor/core.c +0 -0
 	nor = devm_kzalloc(&spi->dev, sizeof(*nor), GFP_KERNEL);
 	if (!nor)
 		return -ENOMEM;
Signature · 7 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/