mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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,
	 Roman Vivchar <rva333@protonmail.com>,
	linux-spi@vger.kernel.org,  linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	 linux-kernel@vger.kernel.org
Subject: [PATCH v2] spi: mt65xx: set host->max_speed_hz in probe
Date: Fri, 27 Nov 2026 02:49:58 +0000	[thread overview]
Message-ID: <20261127024958.8686-1-iasnezhkov@gmail.com> (raw)

From: Ilia Snezhkov <iasnezhkov@gmail.com>

spi-mt65xx leaves host->max_speed_hz unset (0). When a client device
omits spi-max-frequency in DT, spi_setup() keeps spi->max_speed_hz == 0,
and transfers or spi-mem ops without an explicit speed reach
mtk_spi_prepare_transfer() with speed_hz == 0 and mtk_spi_transfer_wait()
with mem->spi->max_speed_hz == 0, causing division by zero in both
DIV_ROUND_UP(mdata->spi_clk_hz, speed_hz) and
div_u64(ms, mem->spi->max_speed_hz).

Validate that spi_clk_hz is at least 2 Hz and set host->max_speed_hz to
mdata->spi_clk_hz / 2 (the controller's maximum SCK rate at div = 1,
sck_time = 1) so the SPI core populates spi->max_speed_hz,
xfer->speed_hz, and op->max_freq for all transfer paths.

Fixes: a568231f4632 ("spi: mediatek: Add spi bus for Mediatek MT8173")
Suggested-by: Roman Vivchar <rva333@protonmail.com>
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
Changes in v2:
- Set host->max_speed_hz = mdata->spi_clk_hz / 2 in mtk_spi_probe()
  (and reject spi_clk_hz < 2) instead of only guarding speed_hz in
  mtk_spi_prepare_transfer(), covering mtk_spi_transfer_wait() as well
  (suggested by Roman Vivchar).
- Move AI coding assistant disclosure below ---.
- Link to v1: https://lore.kernel.org/r/20261126003314.49090-1-iasnezhkov@gmail.com

Found and drafted with an AI coding assistant.

 drivers/spi/spi-mt65xx.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 8b4deef..7e94b4d 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -1285,6 +1285,14 @@ static int mtk_spi_probe(struct platform_device *pdev)
 	}
 
 	mdata->spi_clk_hz = clk_get_rate(mdata->spi_clk);
+	if (mdata->spi_clk_hz < 2) {
+		clk_disable_unprepare(mdata->spi_clk);
+		clk_disable_unprepare(mdata->spi_hclk);
+		return dev_err_probe(dev, -EINVAL, "invalid spi-clk rate %u\n",
+				     mdata->spi_clk_hz);
+	}
+
+	host->max_speed_hz = mdata->spi_clk_hz / 2;
 
 	if (mdata->dev_comp->no_need_unprepare) {
 		clk_disable(mdata->spi_clk);
-- 
2.54.0 (Apple Git-157)




                 reply	other threads:[~2026-11-27  2:50 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=20261127024958.8686-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 \
    --cc=rva333@protonmail.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®