Skip to contentSkip to conversation

spi: Fix regression when the SPI controller does not pass max_speed_hz

PATCH In review Fabio Estevam 3 participants 3 messages Dec 29, 2020 – Dec 30, 2020 SPI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 spi: Fix regression when the SPI controller does not pass max_speed_hz

Since commit 9326e4f1e5dd ("spi: Limit the spi device max speed to controller's max speed") the following regression is observed on an imx6q-sabresd:

[    3.918284] spi_imx 2008000.spi: cannot set clock freq: 0 (base freq: 60000000)
[    3.925953] Division by zero in kernel.
[    3.929831] CPU: 1 PID: 1 Comm: swapper/0 Tainted: G        W         5.10.0-next-20201223 #276
[    3.938565] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[    3.945124] [<c0111a68>] (unwind_backtrace) from [<c010c068>] (show_stack+0x10/0x14)
[    3.952925] [<c010c068>] (show_stack) from [<c0e11540>] (dump_stack+0xe0/0x10c)
[    3.960279] [<c0e11540>] (dump_stack) from [<c05d471c>] (Ldiv0+0x8/0x10)
[    3.967026] [<c05d471c>] (Ldiv0) from [<c089b044>] (mx51_ecspi_prepare_transfer+0xfc/0x17c)

The spi-imx driver does not fill the max_speed_hz field, so we get:

spi->max_speed_hz = 20MHz
spi->controller->max_speed_hz = 0MHz

which will result in spi->max_speed_hz being 0, causing the division by zero in the spi-imx driver.

Fix this problem, by checking if spi->controller->max_speed_hz is not zero prior to assign it to spi->max_speed_hz.

Fixes 9326e4f1e5dd ("spi: Limit the spi device max speed to controller's max speed")

---
Changes since v1:
- Do not add unneeded parenthesis.

 drivers/spi/spi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi.c +2 -1
index 51d7c004fbab..e786a94960d5 100644
@@ -3380,7 +3380,8 @@ int spi_setup(struct spi_device *spi)
 
 	if (!spi->max_speed_hz ||
 	    spi->max_speed_hz > spi->controller->max_speed_hz)
-		spi->max_speed_hz = spi->controller->max_speed_hz;
+		if (spi->controller->max_speed_hz)
+			spi->max_speed_hz = spi->controller->max_speed_hz;
 
 	mutex_lock(&spi->controller->io_mutex);
 
Signature · 1 line
2.17.1
#1 lore raw

Hi Fabio,

Quoted 18 lines · Fabio Estevam

Since commit 9326e4f1e5dd ("spi: Limit the spi device max speed to controller's max speed") the following regression is observed on an imx6q-sabresd:

[    3.918284] spi_imx 2008000.spi: cannot set clock freq: 0 (base freq: 60000000)
[    3.925953] Division by zero in kernel.
[    3.929831] CPU: 1 PID: 1 Comm: swapper/0 Tainted: G        W         5.10.0-next-20201223 #276
[    3.938565] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[    3.945124] [<c0111a68>] (unwind_backtrace) from [<c010c068>] (show_stack+0x10/0x14)
[    3.952925] [<c010c068>] (show_stack) from [<c0e11540>] (dump_stack+0xe0/0x10c)
[    3.960279] [<c0e11540>] (dump_stack) from [<c05d471c>] (Ldiv0+0x8/0x10)
[    3.967026] [<c05d471c>] (Ldiv0) from [<c089b044>] (mx51_ecspi_prepare_transfer+0xfc/0x17c)

The spi-imx driver does not fill the max_speed_hz field, so we get:

spi->max_speed_hz = 20MHz
spi->controller->max_speed_hz = 0MHz

Quoted 8 lines

which will result in spi->max_speed_hz being 0, causing the division by zero in the spi-imx driver.

Fix this problem, by checking if spi->controller->max_speed_hz is not zero prior to assign it to spi->max_speed_hz.

Fixes 9326e4f1e5dd ("spi: Limit the spi device max speed to controller's max speed")

See also
https://lore.kernel.org/linux-spi/[email protected]/

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds