From: Bough Chen <haibo.chen@nxp.com>
To: Lee Jones <lee@kernel.org>, Han Xu <han.xu@nxp.com>,
Mark Brown <broonie@kernel.org>,
Boris Brezillon <bbrezillon@kernel.org>,
Frieder Schrempf <frieder.schrempf@kontron.de>,
Yogesh Gaur <yogeshnarayan.gaur@nxp.com>,
Suresh Gupta <suresh.gupta@nxp.com>,
"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
"imx@lists.linux.dev" <imx@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE: [PATCH v2 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem()
Date: Mon, 30 Nov 2026 03:32:32 +0000 [thread overview]
Message-ID: <AS8PR04MB8820447FA927F9EDDF7D478E904E2@AS8PR04MB8820.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20261127153158.2969573-9-lee@kernel.org>
> -----Original Message-----
> From: Lee Jones <lee@kernel.org>
> Sent: Friday, November 27, 2026 11:31 PM
> To: lee@kernel.org; Han Xu <han.xu@nxp.com>; Mark Brown
> <broonie@kernel.org>; Boris Brezillon <bbrezillon@kernel.org>; Frieder Schrempf
> <frieder.schrempf@kontron.de>; Yogesh Gaur <yogeshnarayan.gaur@nxp.com>;
> Suresh Gupta <suresh.gupta@nxp.com>; linux-spi@vger.kernel.org;
> imx@lists.linux.dev; linux-kernel@vger.kernel.org
> Cc: stable@vger.kernel.org
> Subject: [PATCH v2 08/10] spi: fsl-qspi: Propagate clock errors from
> fsl_qspi_select_mem()
>
> 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.de/
> v%2F%23%2Fbug%2Flinux-719261ef-312e-4a94-9a84-
> fd42a411bee0&data=05%7C02%7Chaibo.chen%40nxp.com%7C01c8ea5e100b42
> aeddd508df4c9bbaad%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C
> 639313903890778872%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRy
> dWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D
> %3D%7C0%7C%7C%7C&sdata=yIbMbFKrgOd4Vx0kE1Hl4B7JoYmlXtVsoS8L7KHpA
> 4s%3D&reserved=0
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
Regards
Haibo Chen
> ---
> 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
>
next prev parent reply other threads:[~2026-11-30 3:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
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 01/10] spi: fsl-cpm: Map the zero page's address, not its struct page Lee Jones
2026-11-27 15:31 ` [PATCH v2 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device Lee Jones
2026-11-27 15:31 ` [PATCH v2 03/10] spi: ch341: Limit transfers to the hardware packet size Lee Jones
2026-11-27 15:31 ` [PATCH v2 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure Lee Jones
2026-11-27 15:31 ` [PATCH v2 05/10] spi: topcliff-pch: Advance tx_buf between DMA chunks Lee Jones
2026-11-27 15:31 ` [PATCH v2 06/10] spi: cadence-quadspi: Validate num-cs against CQSPI_MAX_CHIPSELECT Lee Jones
2026-11-27 17:22 ` Théo Lebrun
2026-11-27 15:31 ` [PATCH v2 07/10] spi: cadence-xspi: Zero the tail word in m_iowriteq() Lee Jones
2026-11-27 15:31 ` [PATCH v2 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem() Lee Jones
2026-11-30 3:32 ` Bough Chen [this message]
2026-12-01 9:05 ` Frieder Schrempf
2026-11-27 15:31 ` [PATCH v2 09/10] spi: cadence-xspi: Advance tx pointer between Marvell b0 chunks Lee Jones
2026-11-27 15:31 ` [PATCH v2 10/10] spi: cadence-xspi: Skip tail read for qword-aligned Marvell b0 receives Lee Jones
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=AS8PR04MB8820447FA927F9EDDF7D478E904E2@AS8PR04MB8820.eurprd04.prod.outlook.com \
--to=haibo.chen@nxp.com \
--cc=bbrezillon@kernel.org \
--cc=broonie@kernel.org \
--cc=frieder.schrempf@kontron.de \
--cc=han.xu@nxp.com \
--cc=imx@lists.linux.dev \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=suresh.gupta@nxp.com \
--cc=yogeshnarayan.gaur@nxp.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®