Skip to contentSkip to conversation

spi: Fix hang on spi_sync() when driver does not support transfer() call

PATCH Applied Alexander Shiyan 2 participants 2 messages Jan 10, 2025 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: Fix hang on spi_sync() when driver does not support transfer() call

When a driver does not support transfer() call, such as most QSPI drivers, calling spi_sync() (e.g. with the "spi" command) will cause the system to hang. Fix this by adding a function check.

barebox@Mega-Milas Informer SAMA5D2:/ spi -b 1 -c 0 0xaa prefetch abort

pc : [<00000004>]    lr : [<27e266a4>]

sp : 27ff7c78 ip : 27ff7ce8 fp : 27e87410
r10: 27ff7d20 r9 : 00000000 r8 : 23f58128
r7 : 23f33c30 r6 : 27ff7c90 r5 : 27ff7d20 r4 : 27ff7c7c
r3 : 00000000 r2 : 27ff7cc4 r1 : 27ff7c90 r0 : 27ff7d20
Flags: nzCv IRQs off FIQs off Mode SVC_32
[<27e266a4>] (spi_sync+0xc8/0xdc) from [<27e2675c>] (spi_write_then_read+0xa4/0xac) [<27e2675c>] (spi_write_then_read+0xa4/0xac) from [<27e438e4>] (do_spi+0x288/0x3e8) [<27e438e4>] (do_spi+0x288/0x3e8) from [<27e05c38>] (execute_command+0x3c/0x80) [<27e05c38>] (execute_command+0x3c/0x80) from [<27e0ee48>] (run_list_real+0x9a8/0xad8) [<27e0ee48>] (run_list_real+0x9a8/0xad8) from [<27e0e2b4>] (parse_stream_outer+0x138/0x200) [<27e0e2b4>] (parse_stream_outer+0x138/0x200) from [<27e0f180>] (run_shell+0x5c/0x90) [<27e0f180>] (run_shell+0x5c/0x90) from [<27e018b4>] (run_init+0x108/0x288) [<27e018b4>] (run_init+0x108/0x288) from [<27e01a8c>] (start_barebox+0x58/0xb4) [<27e01a8c>] (start_barebox+0x58/0xb4) from [<27e5ee18>] (barebox_non_pbl_start+0xc8/0xe0) [<27e5ee18>] (barebox_non_pbl_start+0xc8/0xe0) from [<27e00004>] (__bare_init_start+0x0/0x10)

---
 drivers/spi/spi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/spi/spi.c +3 -0
index c627d88954..c354c00e72 100644
@@ -357,6 +357,9 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
 	int status;
 	int ret;
 
+	if (!spi->controller->transfer)
+		return -ENOTSUPP;
+
 	status = __spi_validate(spi, message);
 	if (status != 0)
 		return status;
Signature · 1 line
2.39.1
Applied
#1 lore raw
Quoted 23 lines · Alexander Shiyan

When a driver does not support transfer() call, such as most QSPI drivers, calling spi_sync() (e.g. with the "spi" command) will cause the system to hang. Fix this by adding a function check.

barebox@Mega-Milas Informer SAMA5D2:/ spi -b 1 -c 0 0xaa prefetch abort

pc : [<00000004>]    lr : [<27e266a4>]

sp : 27ff7c78 ip : 27ff7ce8 fp : 27e87410
r10: 27ff7d20 r9 : 00000000 r8 : 23f58128
r7 : 23f33c30 r6 : 27ff7c90 r5 : 27ff7d20 r4 : 27ff7c7c
r3 : 00000000 r2 : 27ff7cc4 r1 : 27ff7c90 r0 : 27ff7d20
Flags: nzCv IRQs off FIQs off Mode SVC_32
[<27e266a4>] (spi_sync+0xc8/0xdc) from [<27e2675c>] (spi_write_then_read+0xa4/0xac) [<27e2675c>] (spi_write_then_read+0xa4/0xac) from [<27e438e4>] (do_spi+0x288/0x3e8) [<27e438e4>] (do_spi+0x288/0x3e8) from [<27e05c38>] (execute_command+0x3c/0x80) [<27e05c38>] (execute_command+0x3c/0x80) from [<27e0ee48>] (run_list_real+0x9a8/0xad8) [<27e0ee48>] (run_list_real+0x9a8/0xad8) from [<27e0e2b4>] (parse_stream_outer+0x138/0x200) [<27e0e2b4>] (parse_stream_outer+0x138/0x200) from [<27e0f180>] (run_shell+0x5c/0x90) [<27e0f180>] (run_shell+0x5c/0x90) from [<27e018b4>] (run_init+0x108/0x288) [<27e018b4>] (run_init+0x108/0x288) from [<27e01a8c>] (start_barebox+0x58/0xb4) [<27e01a8c>] (start_barebox+0x58/0xb4) from [<27e5ee18>] (barebox_non_pbl_start+0xc8/0xe0) [<27e5ee18>] (barebox_non_pbl_start+0xc8/0xe0) from [<27e00004>] (__bare_init_start+0x0/0x10)

Quoted 1 line

[...]

Applied, thanks!

[1/1] spi: Fix hang on spi_sync() when driver does not support transfer() call
https://git.pengutronix.de/cgit/barebox/commit/?id=0b1be52382e9 (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>