From: <shao.mingyin@zte.com.cn>
To: <broonie@kernel.org>, <linux-spi@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<pjw@kernel.org>, <samuel.holland@sifive.com>,
<william.zhang@broadcom.com>, <kursad.oney@broadcom.com>,
<jonas.gorski@gmail.com>, <bcm-kernel-feedback-list@broadcom.com>,
<anand.gore@broadcom.com>, <florian.fainelli@broadcom.com>,
<rafal@milecki.pl>, <linux-arm-kernel@lists.infradead.org>,
<sven@kernel.org>, <j@jannau.net>, <neal@gompa.dev>,
<asahi@lists.linux.dev>, <ryan.wanner@microchip.com>,
<nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>,
<claudiu.beznea@tuxon.dev>
Subject: [PATCH v2 2/5] spi: bcm63xx-hsspi: fix division by zero for devices without a max speed
Date: Tue, 10 Nov 2026 23:34:57 +0800 (CST) [thread overview]
Message-ID: <2026111023345770952YKePAJQKAcd2Kxe5M3N@zte.com.cn> (raw)
In-Reply-To: <20261110233450305Smji446Uhvoxa7r8SHEgl@zte.com.cn>
From: Shao Mingyin <shao.mingyin@zte.com.cn>
A SPI device whose max_speed_hz is zero (no spi-max-frequency property,
or created through the spidev sysfs new_device interface without a
speed) leaves the transfer speed at zero. spi_setup() would only clamp
it if host->max_speed_hz was set, which this driver does not do, so
bcm63xx_hsspi_set_clk() divides by zero in DIV_ROUND_UP().
The division does not trap on MIPS or arm64. The quotient is undefined
or zero, so the clock control register is programmed with a meaningless
value.
Clamp the requested rate to 1 Hz before computing the divider.
Fixes: 142168eba9dc ("spi: bcm63xx-hsspi: add bcm63xx HSSPI driver")
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/spi/spi-bcm63xx-hsspi.c b/drivers/spi/spi-bcm63xx-hsspi.c
index abfbf97faf7b..319951fba387 100644
--- a/drivers/spi/spi-bcm63xx-hsspi.c
+++ b/drivers/spi/spi-bcm63xx-hsspi.c
@@ -469,6 +469,9 @@ static void bcm63xx_hsspi_set_clk(struct bcm63xx_hsspi *bs,
unsigned int profile = spi_get_chipselect(spi, 0);
u32 reg;
+ /* A device with max_speed_hz == 0 must not divide by zero */
+ hz = max_t(int, hz, 1);
+
reg = DIV_ROUND_UP(2048, DIV_ROUND_UP(bs->speed_hz, hz));
__raw_writel(CLK_CTRL_ACCUM_RST_ON_LOOP | reg,
bs->regs + HSSPI_PROFILE_CLK_CTRL_REG(profile));
next prev parent reply other threads:[~2026-11-10 15:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` shao.mingyin [this message]
2026-11-10 15:34 ` [PATCH v2 3/5] spi: bcmbca-hsspi: fix division by zero for devices without a max speed 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2026111023345770952YKePAJQKAcd2Kxe5M3N@zte.com.cn \
--to=shao.mingyin@zte.com.cn \
--cc=alexandre.belloni@bootlin.com \
--cc=anand.gore@broadcom.com \
--cc=asahi@lists.linux.dev \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=broonie@kernel.org \
--cc=claudiu.beznea@tuxon.dev \
--cc=florian.fainelli@broadcom.com \
--cc=j@jannau.net \
--cc=jonas.gorski@gmail.com \
--cc=kursad.oney@broadcom.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=neal@gompa.dev \
--cc=nicolas.ferre@microchip.com \
--cc=pjw@kernel.org \
--cc=rafal@milecki.pl \
--cc=ryan.wanner@microchip.com \
--cc=samuel.holland@sifive.com \
--cc=sven@kernel.org \
--cc=william.zhang@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®