* [PATCH] spi: jcore: fix divide-by-zero when speed_hz is zero
@ 2026-10-14 14:18 Weibin Liu
2026-10-15 11:26 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Weibin Liu @ 2026-10-14 14:18 UTC (permalink / raw)
To: broonie, linux-spi; +Cc: linux-kernel, dalias, Guanglei Zhu, stable, Weibin Liu
jcore_spi_baudrate() computes hw->clock_freq / 2 / speed without
validating speed. The SPI core fills transfer.speed_hz from
spi->max_speed_hz when it is zero, and jcore_spi_probe() never sets
host->max_speed_hz, so the clamp in __spi_setup() is skipped. A
spi_device created via the sysfs new_device interface (or a DT node
without spi-max-frequency) therefore has max_speed_hz == 0, and any
SPI_IOC_MESSAGE transfer reaches jcore_spi_baudrate() with speed == 0,
causing a division by zero and a kernel panic.
Clamp speed to a minimum of 1 Hz before the division so the divisor is
never zero. The computed divider then truncates to the register field
width and the transfer simply runs at the slowest supported rate.
Verified by inspection of the __spi_setup() clamp and
__spi_validate()'s speed_hz handling; the division-by-zero path
requires the J-Core controller, which was not available.
Reviewed-by: Guanglei Zhu <zhugl3@xiaopeng.com>
Fixes: 2cb1b3b3ac0a ("spi: add driver for J-Core SPI controller")
Cc: stable@vger.kernel.org # 4.9+
Signed-off-by: Weibin Liu <liuwb@xiaopeng.com>
---
drivers/spi/spi-jcore.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/spi/spi-jcore.c b/drivers/spi/spi-jcore.c
index a75cd61ec7a3..fc87ad98e4e7 100644
--- a/drivers/spi/spi-jcore.c
+++ b/drivers/spi/spi-jcore.c
@@ -84,6 +84,8 @@ static void jcore_spi_baudrate(struct jcore_spi *hw, int speed)
{
if (speed == hw->speed_hz)
return;
+ if (speed <= 0)
+ speed = 1;
hw->speed_hz = speed;
if (speed >= hw->clock_freq / 2)
hw->speed_reg = 0;
---
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
change-id: 20261014-spi-jcore-divzero-beb7d7925838
Best regards,
--
Weibin Liu <liuwb@xiaopeng.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] spi: jcore: fix divide-by-zero when speed_hz is zero
2026-10-14 14:18 [PATCH] spi: jcore: fix divide-by-zero when speed_hz is zero Weibin Liu
@ 2026-10-15 11:26 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-10-15 11:26 UTC (permalink / raw)
To: linux-spi, Weibin Liu; +Cc: linux-kernel, dalias, Guanglei Zhu, stable
On Wed, 14 Oct 2026 22:18:50 +0800, Weibin Liu wrote:
> spi: jcore: fix divide-by-zero when speed_hz is zero
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4
Thanks!
[1/1] spi: jcore: fix divide-by-zero when speed_hz is zero
https://git.kernel.org/broonie/spi/c/7db773075501
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-15 14:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 14:18 [PATCH] spi: jcore: fix divide-by-zero when speed_hz is zero Weibin Liu
2026-10-15 11:26 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®