Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH v2 00/10] spi: Fix DMA, bounds, clock, and chip-select bugs
@ 2026-11-27 15:31 Lee Jones
  2026-11-27 15:31 ` [PATCH v2 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem() Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Lee Jones @ 2026-11-27 15:31 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, Théo Lebrun, Anton Vorontsov, Baolin Wang,
	Bartosz Golaszewski, Boris Brezillon,
	Broadcom internal kernel review list, Chris Boot, Chunyan Zhang,
	Dhruva Gole, Felix Gu, Florian Fainelli, Foon Tan,
	Frieder Schrempf, Gabor Juhos, Giulio Benetti, Graham Moore,
	Grant Likely, Han Xu, imx, Jayshri Pawar, Jisheng Zhang,
	Johan Hovold, Johannes Thumshirn, Konrad Kociolek, Linus Walleij,
	linux-arm-kernel, linux-rpi-kernel, linux-spi, Mark Brown,
	Murugan R, Orson Zhai, Parshuram Thombare, Pratyush Yadav,
	Ray Jui, Scott Branden, Suresh Gupta, Tomoya MORINAGA,
	Vignesh Raghavendra, Witold Sadowski, Yogesh Gaur

These issues were reported by Sashiko.

This v2 series addresses Theo Lebrun's review feedback on
cadence-quadspi (patch 06) and rebases onto spi/for-next.

v1 => v2:
 - Rebase onto spi/for-next.
 - Reject num-cs values exceeding CQSPI_MAX_CHIPSELECT in cqspi_of_get_pdata(), store cs as u32, simplify the commit message, and drop the stable tag in patch 06, per Theo Lebrun's review.

Cc: "Théo Lebrun" <theo.lebrun@bootlin.com>
Cc: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
Cc: Chris Boot <bootc@bootc.net>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Dhruva Gole <d-gole@ti.com>
Cc: Felix Gu <ustc.gu@gmail.com>
Cc: Florian Fainelli <florian.fainelli@broadcom.com>
Cc: Foon Tan <lftan@altera.com>
Cc: Frieder Schrempf <frieder.schrempf@kontron.de>
Cc: Gabor Juhos <juhosg@openwrt.org>
Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
Cc: Graham Moore <grmoore@opensource.altera.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Han Xu <han.xu@nxp.com>
Cc: imx@lists.linux.dev
Cc: Jayshri Pawar <jpawar@cadence.com>
Cc: Jisheng Zhang <jszhang@kernel.org>
Cc: Johan Hovold <johan@kernel.org>
Cc: Johannes Thumshirn <jth@kernel.org>
Cc: Konrad Kociolek <konrad@cadence.com>
Cc: Linus Walleij <linusw@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-rpi-kernel@lists.infradead.org
Cc: linux-spi@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
Cc: Murugan R <vadivel.muruganx.ramuthevar@intel.com>
Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Parshuram Thombare <pthombar@cadence.com>
Cc: Pratyush Yadav <p.yadav@ti.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Suresh Gupta <suresh.gupta@nxp.com>
Cc: Tomoya MORINAGA <tomoya.rohm@gmail.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Witold Sadowski <wsadowski@marvell.com>
Cc: Yogesh Gaur <yogeshnarayan.gaur@nxp.com>

Lee Jones (10):
  spi: fsl-cpm: Map the zero page's address, not its struct page
  spi: bcm2835: Store native chip-select GPIO descriptor per device
  spi: ch341: Limit transfers to the hardware packet size
  spi: sprd-adi: Do not copy uninitialised data to rx_buf on read
    failure
  spi: topcliff-pch: Advance tx_buf between DMA chunks
  spi: cadence-quadspi: Validate num-cs against CQSPI_MAX_CHIPSELECT
  spi: cadence-xspi: Zero the tail word in m_iowriteq()
  spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem()
  spi: cadence-xspi: Advance tx pointer between Marvell b0 chunks
  spi: cadence-xspi: Skip tail read for qword-aligned Marvell b0
    receives

 drivers/spi/spi-bcm2835.c         | 18 +++++++++---------
 drivers/spi/spi-cadence-quadspi.c | 12 +++++++++---
 drivers/spi/spi-cadence-xspi.c    |  8 ++++++--
 drivers/spi/spi-ch341.c           |  6 ++++++
 drivers/spi/spi-fsl-cpm.c         |  3 ++-
 drivers/spi/spi-fsl-qspi.c        | 26 +++++++++++++++++---------
 drivers/spi/spi-sprd-adi.c        |  3 ++-
 drivers/spi/spi-topcliff-pch.c    |  5 +++++
 8 files changed, 56 insertions(+), 25 deletions(-)

-- 
2.56.1.839.g22a8290db9-goog


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

* [PATCH v2 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem()
  2026-11-27 15:31 [PATCH v2 00/10] spi: Fix DMA, bounds, clock, and chip-select bugs Lee Jones
@ 2026-11-27 15:31 ` Lee Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2026-11-27 15:31 UTC (permalink / raw)
  To: lee, Han Xu, Mark Brown, Boris Brezillon, Frieder Schrempf,
	Yogesh Gaur, Suresh Gupta, linux-spi, imx, linux-kernel
  Cc: stable

fsl_qspi_select_mem() returns void and silently gives up if either
clk_set_rate() or fsl_qspi_clk_prep_enable() fails.  fsl_qspi_exec_op()
then carries on with the operation regardless.

When switching between devices, a failed rate change leaves q->selected
pointing at the previously selected chip, so the operation is issued
through the previous device's SFAR and AHB window.  If the failure
happens on the first operation, q->selected is still -1 from probe, so
those offsets are derived from a negative chip select.  On controllers
which need the clocks disabled while the rate is changed, a
clk_set_rate() failure also leaves the clocks off while registers
continue to be accessed.

Re-enable the clocks even when setting the rate failed, return any error
to the caller, and have fsl_qspi_exec_op() abort the operation when
selecting the device fails.

Fixes: 84d043185dbe ("spi: Add a driver for the Freescale/NXP QuadSPI controller")
Closes: https://sashiko.dev/#/bug/linux-719261ef-312e-4a94-9a84-fd42a411bee0
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2:
 - Rebase onto spi/for-next; no functional changes.

 drivers/spi/spi-fsl-qspi.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
index d2c2090442f8..30f39adb5a6b 100644
--- a/drivers/spi/spi-fsl-qspi.c
+++ b/drivers/spi/spi-fsl-qspi.c
@@ -546,15 +546,15 @@ static void fsl_qspi_invalidate(struct fsl_qspi *q)
 	qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
 }
 
-static void fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_device *spi,
-				const struct spi_mem_op *op)
+static int fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_device *spi,
+			       const struct spi_mem_op *op)
 {
 	unsigned long rate = op->max_freq;
 	int ret;
 
 	if (q->selected == spi_get_chipselect(spi, 0) &&
 	    q->selected_freq == op->max_freq)
-		return;
+		return 0;
 
 	if (needs_4x_clock(q))
 		rate *= 4;
@@ -563,19 +563,24 @@ static void fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_device *spi,
 		fsl_qspi_clk_disable_unprep(q);
 
 	ret = clk_set_rate(q->clk, rate);
-	if (ret)
-		return;
 
 	if (needs_clk_disable(q)) {
-		ret = fsl_qspi_clk_prep_enable(q);
-		if (ret)
-			return;
+		int err;
+
+		err = fsl_qspi_clk_prep_enable(q);
+		if (!ret)
+			ret = err;
 	}
 
+	if (ret)
+		return ret;
+
 	q->selected = spi_get_chipselect(spi, 0);
 	q->selected_freq = op->max_freq;
 
 	fsl_qspi_invalidate(q);
+
+	return 0;
 }
 
 static void fsl_qspi_read_ahb(struct fsl_qspi *q, const struct spi_mem_op *op)
@@ -682,7 +687,9 @@ static int fsl_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 	fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR, (QUADSPI_SR_IP_ACC_MASK |
 				 QUADSPI_SR_AHB_ACC_MASK), 10, 1000);
 
-	fsl_qspi_select_mem(q, mem->spi, op);
+	err = fsl_qspi_select_mem(q, mem->spi, op);
+	if (err)
+		goto out_unlock;
 
 	if (needs_amba_base_offset(q))
 		addr_offset = q->memmap_phy;
@@ -725,6 +732,7 @@ static int fsl_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 	/* Invalidate the data in the AHB buffer. */
 	fsl_qspi_invalidate(q);
 
+out_unlock:
 	mutex_unlock(&q->lock);
 
 	return err;
-- 
2.56.1.839.g22a8290db9-goog


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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 15:31 [PATCH v2 00/10] spi: Fix DMA, bounds, clock, and chip-select bugs Lee Jones
2026-11-27 15:31 ` [PATCH v2 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem() Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox