mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/5] spi: fix division by zero with a zero transfer speed
@ 2026-11-10 15:34 shao.mingyin
  2026-11-10 15:34 ` [PATCH v2 1/5] spi: sifive: clamp the clock divider to the register range shao.mingyin
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: shao.mingyin @ 2026-11-10 15:34 UTC (permalink / raw)
  To: broonie, linux-spi
  Cc: linux-kernel, linux-riscv, pjw, samuel.holland, william.zhang,
	kursad.oney, jonas.gorski, bcm-kernel-feedback-list, anand.gore,
	florian.fainelli, rafal, linux-arm-kernel, sven, j, neal, asahi,
	ryan.wanner, nicolas.ferre, alexandre.belloni, claudiu.beznea

Five SPI controller drivers compute a clock divider from the transfer
speed without checking that it is non-zero.  A SPI device whose
max_speed_hz is zero (a DT node without spi-max-frequency, or a device
created through the spidev sysfs new_device interface without a speed)
therefore reaches the division with speed_hz == 0.  The SPI core clamps
such a device to the controller limit only when host->max_speed_hz is
set, and none of these five drivers sets it.

The series is organized by driver and is independent patch-by-patch;
each patch can be applied and reviewed on its own, and taking a subset
is fine:

  1/5 spi: sifive: clamp the clock divider to the register range
  2/5 spi: bcm63xx-hsspi: fix division by zero for devices without a max speed
  3/5 spi: bcmbca-hsspi: fix division by zero for devices without a max speed
  4/5 spi: apple: fix division by zero in clock divisor calculation
  5/5 spi: atmel: use the maximum divider for an unspecified speed

1/5 and 5/5 program the slowest clock directly when no speed is supplied;
2/5-4/5 clamp the requested rate to 1 Hz.  The division does not trap on
the SoCs these drivers run on: depending on the architecture it produces
a bogus divider, a zero quotient or an undefined value, so the patches
remove undefined arithmetic rather than a crash.

Changes in v2:
- 1/5: use the maximum SCKDIV for a zero speed and saturate an excessive
  divider instead of masking away the high bits (Mark Brown).
- 5/5: select SCBR=255 directly for a zero speed instead of dividing a
  substituted 1 Hz and then failing the range check (Mark Brown).
- 2/5, 3/5 and 4/5: unchanged.
- This series replaces the two standalone v2 patches posted on 10 Nov for
  1/5 and 5/5.
Link to v1: https://lore.kernel.org/all/20261106234751020Egf42VCVVlsSC_Msov4HO@zte.com.cn/

Shao Mingyin (5):
  spi: sifive: clamp the clock divider to the register range
  spi: bcm63xx-hsspi: fix division by zero for devices without a max speed
  spi: bcmbca-hsspi: fix division by zero for devices without a max speed
  spi: apple: fix division by zero in clock divisor calculation
  spi: atmel: use the maximum divider for an unspecified speed

 drivers/spi/spi-apple.c         | 6 +++++-
 drivers/spi/spi-atmel.c         | 5 ++++-
 drivers/spi/spi-bcm63xx-hsspi.c | 3 +++
 drivers/spi/spi-bcmbca-hsspi.c  | 3 +++
 drivers/spi/spi-sifive.c        | 9 ++++++---
 5 files changed, 21 insertions(+), 5 deletions(-)

---
base-commit: ddfe51b0a0f5dc9e415cc2c8ad8db17532dd426b

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

end of thread, other threads:[~2026-11-14 14:14 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 15:34 [PATCH v2 0/5] spi: fix division by zero with a zero transfer speed shao.mingyin
2026-11-10 15:34 ` [PATCH v2 1/5] spi: sifive: clamp the clock divider to the register range shao.mingyin
2026-11-10 15:34 ` [PATCH v2 2/5] spi: bcm63xx-hsspi: fix division by zero for devices without a max speed shao.mingyin
2026-11-10 15:34 ` [PATCH v2 3/5] spi: bcmbca-hsspi: " shao.mingyin
2026-11-10 20:30   ` William Zhang
2026-11-11  9:36     ` shao.mingyin
2026-11-14  0:51       ` Mark Brown
2026-11-14  1:13         ` William Zhang
2026-11-14  6:07           ` shao.mingyin
2026-11-14 14:14             ` Mark Brown
2026-11-10 15:35 ` [PATCH v2 4/5] spi: apple: fix division by zero in clock divisor calculation shao.mingyin
2026-11-10 15:35 ` [PATCH v2 5/5] spi: atmel: use the maximum divider for an unspecified speed shao.mingyin
2026-11-10 16:14 ` [PATCH v2 0/5] spi: fix division by zero with a zero transfer speed Mark Brown
2026-11-11  9:36   ` shao.mingyin
2026-11-13 22:07 ` Mark Brown
2026-11-14  0:39   ` William Zhang
2026-11-14  0:57     ` Mark Brown
2026-11-14  1:11       ` William Zhang

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®