linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi-nor: fix spi_nor_probe
@ 2022-04-25 13:58 Pascal Fabreges
  2022-04-29  6:33 ` Pratyush Yadav
  0 siblings, 1 reply; 2+ messages in thread
From: Pascal Fabreges @ 2022-04-25 13:58 UTC (permalink / raw)
  To: linux-mtd
  Cc: Tudor Ambarus, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, wladislav.wiebe, alexander.sverdlin,
	agathe.porte, matthias.robert

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

Signed-off-by: Pascal Fabreges <pascal.fabreges@nokia.com>
---
 drivers/mtd/spi-nor/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index e6b8b19a68ee..dd82f42c29db 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -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;
-- 
2.32.0


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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] spi-nor: fix spi_nor_probe
  2022-04-25 13:58 [PATCH] spi-nor: fix spi_nor_probe Pascal Fabreges
@ 2022-04-29  6:33 ` Pratyush Yadav
  0 siblings, 0 replies; 2+ messages in thread
From: Pratyush Yadav @ 2022-04-29  6:33 UTC (permalink / raw)
  To: Pascal Fabreges
  Cc: linux-mtd, Tudor Ambarus, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, wladislav.wiebe, alexander.sverdlin,
	agathe.porte, matthias.robert

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.

On 25/04/22 01:58PM, Pascal Fabreges wrote:
> 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
> 
> Signed-off-by: Pascal Fabreges <pascal.fabreges@nokia.com>
> ---
>  drivers/mtd/spi-nor/core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index e6b8b19a68ee..dd82f42c29db 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -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.

>  	nor = devm_kzalloc(&spi->dev, sizeof(*nor), GFP_KERNEL);
>  	if (!nor)
>  		return -ENOMEM;

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-29  6:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25 13:58 [PATCH] spi-nor: fix spi_nor_probe Pascal Fabreges
2022-04-29  6:33 ` Pratyush Yadav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).