From: Ilia Snezhkov via B4 Relay <devnull+iasnezhkov.gmail.com@kernel.org>
To: broonie@kernel.org
Cc: matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
linux-spi@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] spi: mt65xx: avoid division by zero when speed_hz is zero
Date: Thu, 26 Nov 2026 00:33:14 +0000 [thread overview]
Message-ID: <20261126003314.49090-1-iasnezhkov@gmail.com> (raw)
From: Ilia Snezhkov <iasnezhkov@gmail.com>
spi-mt65xx does not set host->max_speed_hz, so if a slave device omits
spi-max-frequency in DT and a transfer leaves speed_hz unset,
__spi_validate() passes speed_hz == 0 to mtk_spi_prepare_transfer().
Because 0 < mdata->spi_clk_hz / 2 is true, DIV_ROUND_UP(mdata->spi_clk_hz,
speed_hz) divides by zero (undefined behavior; on arm64 udiv returns 0,
which then underflows sck_time - 1 to 0xffff).
Guard the division on speed_hz != 0 so zero speed falls back to div = 1.
Found and drafted with an AI coding assistant.
Fixes: a568231f4632 ("spi: mediatek: Add spi bus for Mediatek MT8173")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
drivers/spi/spi-mt65xx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 8b4deef..2baea0c 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -509,7 +509,7 @@ static void mtk_spi_prepare_transfer(struct spi_controller *host,
u32 div, sck_time, reg_val;
struct mtk_spi *mdata = spi_controller_get_devdata(host);
- if (speed_hz < mdata->spi_clk_hz / 2)
+ if (speed_hz && speed_hz < mdata->spi_clk_hz / 2)
div = DIV_ROUND_UP(mdata->spi_clk_hz, speed_hz);
else
div = 1;
--
2.54.0 (Apple Git-157)
reply other threads:[~2026-11-26 0:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261126003314.49090-1-iasnezhkov@gmail.com \
--to=devnull+iasnezhkov.gmail.com@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=broonie@kernel.org \
--cc=iasnezhkov@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=matthias.bgg@gmail.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®