* [PATCH 01/10] spi: fsl-cpm: Map the zero page's address, not its struct page
[not found] <20261119091810.3440619-1-lee@kernel.org>
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 9:17 ` [PATCH 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device Lee Jones
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Anton Vorontsov, Giulio Benetti, linux-spi,
linux-kernel
Cc: stable
fsl_spi_cpm_init() maps a dummy TX buffer which is used for transfers
that have no tx_buf. Since the conversion from empty_zero_page to
ZERO_PAGE(0), the struct page pointer returned by ZERO_PAGE() has been
handed directly to dma_map_single(), which expects a kernel virtual
address.
As a result the mapping covers a PAGE_SIZE window of the memory map
rather than a page of zeroes, and that struct page metadata is then
clocked out onto the SPI bus for every RX-only transfer.
Pass page_address(ZERO_PAGE(0)) instead, so that the zero page itself is
mapped.
Fixes: 3be6acda8241 ("spi: fsl-cpm: substitute empty_zero_page with helper ZERO_PAGE(0)")
Closes: https://sashiko.dev/#/bug/linux-8dbfe527-3ba3-488a-a6fb-d4ee650b8ca7
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-fsl-cpm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c
index 23ad1249f121..ccdd62f3c74b 100644
--- a/drivers/spi/spi-fsl-cpm.c
+++ b/drivers/spi/spi-fsl-cpm.c
@@ -350,7 +350,8 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
goto err_bds;
}
- mspi->dma_dummy_tx = dma_map_single(dev, ZERO_PAGE(0), PAGE_SIZE,
+ mspi->dma_dummy_tx = dma_map_single(dev, page_address(ZERO_PAGE(0)),
+ PAGE_SIZE,
DMA_TO_DEVICE);
if (dma_mapping_error(dev, mspi->dma_dummy_tx)) {
dev_err(dev, "unable to map dummy tx buffer\n");
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device
[not found] <20261119091810.3440619-1-lee@kernel.org>
2026-11-19 9:17 ` [PATCH 01/10] spi: fsl-cpm: Map the zero page's address, not its struct page Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 9:17 ` [PATCH 03/10] spi: ch341: Limit transfers to the hardware packet size Lee Jones
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Gabor Juhos, Chris Boot,
Linus Walleij, Bartosz Golaszewski, linux-spi, linux-rpi-kernel,
linux-arm-kernel, linux-kernel
Cc: stable
When a device uses a native chip-select, bcm2835_spi_setup() requests a
GPIO descriptor for it and stores the result in the controller-wide
bs->cs_gpio. A second device using a native chip-select overwrites the
first device's descriptor, which is then leaked.
bcm2835_spi_cleanup() subsequently calls gpiod_put(bs->cs_gpio) for
every device, including devices whose chip-select was requested by the
SPI core from the cs-gpios property. The same descriptor can therefore
be released several times, and the descriptor released is not
necessarily the one which belongs to the device being cleaned up.
Move the descriptor into the per-device struct bcm2835_spidev, which is
zero-initialised, so that each device releases only the descriptor it
requested itself.
Fixes: 21f252cd29f0 ("spi: bcm2835: reduce the abuse of the GPIO API")
Closes: https://sashiko.dev/#/bug/linux-677b4cdb-2c6c-4cad-8a5a-45a24dc5cbab
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-bcm2835.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index 9d589df90933..af118cccee1b 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -85,7 +85,6 @@ MODULE_PARM_DESC(polling_limit_us,
* struct bcm2835_spi - BCM2835 SPI controller
* @regs: base address of register map
* @clk: core clock, divided to calculate serial clock
- * @cs_gpio: chip-select GPIO descriptor
* @clk_hz: core clock cached speed
* @irq: interrupt, signals TX FIFO empty or RX FIFO ¾ full
* @tfr: SPI transfer currently processed
@@ -120,7 +119,6 @@ MODULE_PARM_DESC(polling_limit_us,
struct bcm2835_spi {
void __iomem *regs;
struct clk *clk;
- struct gpio_desc *cs_gpio;
unsigned long clk_hz;
int irq;
struct spi_transfer *tfr;
@@ -153,6 +151,7 @@ struct bcm2835_spi {
* @clear_rx_desc: preallocated RX DMA descriptor used for TX-only transfers
* (cyclically clears RX FIFO by writing @clear_rx_cs to CS register)
* @clear_rx_addr: bus address of @clear_rx_cs
+ * @cs_gpio: native chip-select GPIO descriptor requested by the driver
* @clear_rx_cs: precalculated CS register value to clear RX FIFO
* (uses target-specific clock polarity and phase settings)
*/
@@ -160,6 +159,7 @@ struct bcm2835_spidev {
u32 prepare_cs;
struct dma_async_tx_descriptor *clear_rx_desc;
dma_addr_t clear_rx_addr;
+ struct gpio_desc *cs_gpio;
u32 clear_rx_cs ____cacheline_aligned;
};
@@ -1157,7 +1157,6 @@ static void bcm2835_spi_cleanup(struct spi_device *spi)
{
struct bcm2835_spidev *target = spi_get_ctldata(spi);
struct spi_controller *ctlr = spi->controller;
- struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
if (target->clear_rx_desc)
dmaengine_desc_free(target->clear_rx_desc);
@@ -1168,8 +1167,7 @@ static void bcm2835_spi_cleanup(struct spi_device *spi)
sizeof(u32),
DMA_TO_DEVICE);
- if (!IS_ERR(bs->cs_gpio))
- gpiod_put(bs->cs_gpio);
+ gpiod_put(target->cs_gpio);
spi_set_csgpiod(spi, 0, NULL);
kfree(target);
@@ -1232,6 +1230,7 @@ static int bcm2835_spi_setup(struct spi_device *spi)
struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
struct bcm2835_spidev *target = spi_get_ctldata(spi);
struct gpiod_lookup_table *lookup __free(kfree) = NULL;
+ struct gpio_desc *cs_gpio;
static const char * const pinctrl_compats[] = {
"brcm,bcm2835-gpio",
"brcm,bcm2711-gpio",
@@ -1334,14 +1333,15 @@ static int bcm2835_spi_setup(struct spi_device *spi)
gpiod_add_lookup_table(lookup);
- bs->cs_gpio = gpiod_get(&spi->dev, "cs", GPIOD_OUT_LOW);
+ cs_gpio = gpiod_get(&spi->dev, "cs", GPIOD_OUT_LOW);
gpiod_remove_lookup_table(lookup);
- if (IS_ERR(bs->cs_gpio)) {
- ret = PTR_ERR(bs->cs_gpio);
+ if (IS_ERR(cs_gpio)) {
+ ret = PTR_ERR(cs_gpio);
goto err_cleanup;
}
- spi_set_csgpiod(spi, 0, bs->cs_gpio);
+ target->cs_gpio = cs_gpio;
+ spi_set_csgpiod(spi, 0, cs_gpio);
/* and set up the "mode" and level */
dev_info(&spi->dev, "setting up native-CS%i to use GPIO\n",
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 03/10] spi: ch341: Limit transfers to the hardware packet size
[not found] <20261119091810.3440619-1-lee@kernel.org>
2026-11-19 9:17 ` [PATCH 01/10] spi: fsl-cpm: Map the zero page's address, not its struct page Lee Jones
2026-11-19 9:17 ` [PATCH 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 9:17 ` [PATCH 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure Lee Jones
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Johan Hovold, Johannes Thumshirn, linux-spi,
linux-kernel
Cc: stable
ch341_transfer_one() clamps each transfer to CH341_PACKET_LENGTH bytes,
of which the first is the command byte, so at most 31 data bytes are
moved. It nevertheless reports success for the whole transfer.
The driver does not provide a max_transfer_size() callback, so the SPI
core never splits longer transfers. The remainder of the data is
silently dropped, and on the receive side the caller sees whatever was
already in its buffer. For spidev this means stale or uninitialised
kernel heap from its bounce buffer is copied out to user space.
Report the real limit through max_transfer_size() so that the SPI core
splits long transfers into chunks the hardware can handle.
Fixes: 8846739f52af ("spi: add ch341a usb2spi driver")
Closes: https://sashiko.dev/#/bug/linux-a21e23dc-14b5-4ed1-bfba-f508132e11a0
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-ch341.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/spi/spi-ch341.c b/drivers/spi/spi-ch341.c
index 56a5caa5975a..0783a2d39a61 100644
--- a/drivers/spi/spi-ch341.c
+++ b/drivers/spi/spi-ch341.c
@@ -63,6 +63,11 @@ static void ch341_set_cs(struct spi_device *spi, bool is_high)
"error sending USB message for setting CS (%d)\n", err);
}
+static size_t ch341_max_transfer_size(struct spi_device *spi)
+{
+ return CH341_PACKET_LENGTH - 1;
+}
+
static int ch341_transfer_one(struct spi_controller *host,
struct spi_device *spi,
struct spi_transfer *trans)
@@ -187,6 +192,7 @@ static int ch341_probe(struct usb_interface *intf,
ctrl->bus_num = -1;
ctrl->mode_bits = SPI_CPHA;
ctrl->transfer_one = ch341_transfer_one;
+ ctrl->max_transfer_size = ch341_max_transfer_size;
ctrl->set_cs = ch341_set_cs;
ctrl->auto_runtime_pm = false;
/*
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure
[not found] <20261119091810.3440619-1-lee@kernel.org>
` (2 preceding siblings ...)
2026-11-19 9:17 ` [PATCH 03/10] spi: ch341: Limit transfers to the hardware packet size Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 9:17 ` [PATCH 05/10] spi: topcliff-pch: Advance tx_buf between DMA chunks Lee Jones
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Orson Zhai, Baolin Wang, Chunyan Zhang, Felix Gu,
linux-spi, linux-kernel
Cc: stable
sprd_adi_read() returns early without writing to *read_val if it fails
to take the hardware spinlock, if the register address is out of range,
if the read times out or if the read-back check fails.
sprd_adi_transfer_one() stores val into rx_buf regardless of the return
value, so on any of those failures the caller's buffer is filled with
uninitialised stack data.
Only update rx_buf when the read succeeded. The error code is still
propagated as before.
Fixes: 5dc349ec131c ("spi: sprd: Pass offset instead of physical address to adi_read/_write()")
Closes: https://sashiko.dev/#/bug/linux-4e21848f-9195-4645-a277-501803f17e95
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-sprd-adi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c
index a6baaf02b3c8..3586fc1aac7b 100644
--- a/drivers/spi/spi-sprd-adi.c
+++ b/drivers/spi/spi-sprd-adi.c
@@ -341,7 +341,8 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
if (t->rx_buf) {
reg = *(u32 *)t->rx_buf;
ret = sprd_adi_read(sadi, reg, &val);
- *(u32 *)t->rx_buf = val;
+ if (!ret)
+ *(u32 *)t->rx_buf = val;
} else if (t->tx_buf) {
u32 *p = (u32 *)t->tx_buf;
reg = *p++;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 05/10] spi: topcliff-pch: Advance tx_buf between DMA chunks
[not found] <20261119091810.3440619-1-lee@kernel.org>
` (3 preceding siblings ...)
2026-11-19 9:17 ` [PATCH 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 9:17 ` [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size Lee Jones
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Tomoya MORINAGA, Grant Likely, linux-spi,
linux-kernel
Cc: stable
In DMA mode, pch_spi_process_messages() splits transfers larger than
PCH_BUF_SIZE into chunks and calls pch_spi_handle_dma() once per chunk.
pch_spi_handle_dma() copies the TX data through a local pointer and
never stores the advanced position back into the transfer, so every
chunk after the first retransmits the data from the first chunk.
The RX side already writes its advanced pointer back and restores the
original rx_buf once the transfer is complete.
Do the same for tx_buf, so that each chunk sends the correct slice of
the buffer, and restore the original tx_buf once the transfer has
completed or failed.
Advancing tx_buf by the number of bytes copied relies on the following
commit, which ensures that each chunk covers no more than the bytes
accounted for by the loop in pch_spi_process_messages():
commit 3515e312e096 ("spi: topcliff-pch: clamp DMA bpw_len by bytes not words")
Fixes: 7d05b3e868ee ("spi-topcliff-pch: Fix issue for transmitting over 4KByte")
Closes: https://sashiko.dev/#/bug/linux-625e2f07-fb68-446b-b1a8-b1f66aacb62e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-topcliff-pch.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index 0bec3012a6bc..cbe76c4ae2e8 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -947,11 +947,13 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw)
tx_dma_buf = dma->tx_buf_virt;
for (i = 0; i < data->bpw_len; i++)
*tx_dma_buf++ = *tx_buf++;
+ data->cur_trans->tx_buf = tx_buf;
} else {
tx_sbuf = data->cur_trans->tx_buf;
tx_dma_sbuf = dma->tx_buf_virt;
for (i = 0; i < data->bpw_len; i++)
*tx_dma_sbuf++ = *tx_sbuf++;
+ data->cur_trans->tx_buf = tx_sbuf;
}
}
@@ -1180,10 +1182,12 @@ static void pch_spi_process_messages(struct work_struct *pwork)
if (data->use_dma) {
int i;
char *save_rx_buf = data->cur_trans->rx_buf;
+ const void *save_tx_buf = data->cur_trans->tx_buf;
for (i = 0; i < cnt; i++) {
pch_spi_handle_dma(data, &bpw);
if (!pch_spi_start_transfer(data)) {
+ data->cur_trans->tx_buf = save_tx_buf;
data->transfer_complete = true;
data->current_msg->status = -EIO;
data->current_msg->complete
@@ -1196,6 +1200,7 @@ static void pch_spi_process_messages(struct work_struct *pwork)
pch_spi_copy_rx_data_for_dma(data, bpw);
}
data->cur_trans->rx_buf = save_rx_buf;
+ data->cur_trans->tx_buf = save_tx_buf;
} else {
pch_spi_set_tx(data, &bpw);
pch_spi_set_ir(data);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size
[not found] <20261119091810.3440619-1-lee@kernel.org>
` (4 preceding siblings ...)
2026-11-19 9:17 ` [PATCH 05/10] spi: topcliff-pch: Advance tx_buf between DMA chunks Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 10:15 ` Théo Lebrun
2026-11-19 9:17 ` [PATCH 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem() Lee Jones
` (2 subsequent siblings)
8 siblings, 1 reply; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Foon Tan, Graham Moore, Murugan R,
Vignesh Raghavendra, Pratyush Yadav, Théo Lebrun,
Dhruva Gole, linux-spi, linux-kernel
Cc: stable
cqspi_setup_flash() uses the chip select taken from each flash child
node's reg property to index the fixed-size cqspi->f_pdata[] array,
which has CQSPI_MAX_CHIPSELECT entries.
The range check now compares the chip select against num_chipselect,
which comes straight from the num-cs property and is never clamped to
CQSPI_MAX_CHIPSELECT. A device tree which specifies num-cs greater than
CQSPI_MAX_CHIPSELECT together with a flash node at a correspondingly
high reg value therefore causes writes beyond the end of f_pdata[].
Reject chip selects which do not fit in f_pdata[] as well as those which
exceed num-cs. While at it, store the chip select in a u32, matching
of_property_read_u32(), so that values with the top bit set cannot
become negative and slip past the bounds checks.
Fixes: 0d62c64a8e48 ("spi: cadence-qspi: assert each subnode flash CS is valid")
Closes: https://sashiko.dev/#/bug/linux-cd463fc8-1b94-4bcf-8d06-fae21b88894c
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-cadence-quadspi.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 844df97111d7..fbb917c104b0 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -1751,7 +1751,8 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
struct platform_device *pdev = cqspi->pdev;
struct device *dev = &pdev->dev;
struct cqspi_flash_pdata *f_pdata;
- int ret, cs, max_cs = -1;
+ int ret, max_cs = -1;
+ u32 cs;
/* Get flash device data */
for_each_available_child_of_node_scoped(dev->of_node, np) {
@@ -1761,8 +1762,9 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
return ret;
}
- if (cs >= cqspi->num_chipselect) {
- dev_err(dev, "Chip select %d out of range.\n", cs);
+ if (cs >= cqspi->num_chipselect ||
+ cs >= CQSPI_MAX_CHIPSELECT) {
+ dev_err(dev, "Chip select %u out of range.\n", cs);
return -EINVAL;
}
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size
2026-11-19 9:17 ` [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size Lee Jones
@ 2026-11-19 10:15 ` Théo Lebrun
2026-11-19 14:33 ` Lee Jones
0 siblings, 1 reply; 12+ messages in thread
From: Théo Lebrun @ 2026-11-19 10:15 UTC (permalink / raw)
To: Lee Jones, Mark Brown, Foon Tan, Graham Moore, Murugan R,
Vignesh Raghavendra, Pratyush Yadav, Dhruva Gole, linux-spi,
linux-kernel, Miquèl Raynal, Thomas Petazzoni
Cc: stable
Hello Lee,
On Thu Nov 19, 2026 at 10:17 AM CET, Lee Jones wrote:
> cqspi_setup_flash() uses the chip select taken from each flash child
> node's reg property to index the fixed-size cqspi->f_pdata[] array,
> which has CQSPI_MAX_CHIPSELECT entries.
>
> The range check now compares the chip select against num_chipselect,
> which comes straight from the num-cs property and is never clamped to
> CQSPI_MAX_CHIPSELECT. A device tree which specifies num-cs greater than
> CQSPI_MAX_CHIPSELECT together with a flash node at a correspondingly
> high reg value therefore causes writes beyond the end of f_pdata[].
>
> Reject chip selects which do not fit in f_pdata[] as well as those which
> exceed num-cs. While at it, store the chip select in a u32, matching
> of_property_read_u32(), so that values with the top bit set cannot
> become negative and slip past the bounds checks.
This commit message was hard to read! Can we do better?
The issue at hand is super simple.
Repeating the last sentence:
> While at it, store the chip select in a u32, matching
> of_property_read_u32(), so that values with the top bit set cannot
> become negative and slip past the bounds checks.
Come on! 2147483648 chip selects?
> Fixes: 0d62c64a8e48 ("spi: cadence-qspi: assert each subnode flash CS is valid")
> Closes: https://sashiko.dev/#/bug/linux-cd463fc8-1b94-4bcf-8d06-fae21b88894c
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
Is this worthy of backporting to all stable releases? It is a indeed
a bug fix but which can only occur with a broken DT, probably during
development. It sounds like a lot of churn.
> ---
> drivers/spi/spi-cadence-quadspi.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
> index 844df97111d7..fbb917c104b0 100644
> --- a/drivers/spi/spi-cadence-quadspi.c
> +++ b/drivers/spi/spi-cadence-quadspi.c
> @@ -1751,7 +1751,8 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
> struct platform_device *pdev = cqspi->pdev;
> struct device *dev = &pdev->dev;
> struct cqspi_flash_pdata *f_pdata;
> - int ret, cs, max_cs = -1;
> + int ret, max_cs = -1;
> + u32 cs;
>
> /* Get flash device data */
> for_each_available_child_of_node_scoped(dev->of_node, np) {
> @@ -1761,8 +1762,9 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
> return ret;
> }
>
> - if (cs >= cqspi->num_chipselect) {
> - dev_err(dev, "Chip select %d out of range.\n", cs);
> + if (cs >= cqspi->num_chipselect ||
> + cs >= CQSPI_MAX_CHIPSELECT) {
> + dev_err(dev, "Chip select %u out of range.\n", cs);
> return -EINVAL;
> }
OK this does fix the bug. Here is another proposal though:
ensure at probe that cqspi->num_chipselect <= CQSPI_MAX_CHIPSELECT.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size
2026-11-19 10:15 ` Théo Lebrun
@ 2026-11-19 14:33 ` Lee Jones
2026-11-19 14:55 ` Théo Lebrun
0 siblings, 1 reply; 12+ messages in thread
From: Lee Jones @ 2026-11-19 14:33 UTC (permalink / raw)
To: Théo Lebrun
Cc: Mark Brown, Foon Tan, Graham Moore, Murugan R,
Vignesh Raghavendra, Pratyush Yadav, Dhruva Gole, linux-spi,
linux-kernel, Miquèl Raynal, Thomas Petazzoni, stable
On Thu, 19 Nov 2026, Théo Lebrun wrote:
> Hello Lee,
>
> On Thu Nov 19, 2026 at 10:17 AM CET, Lee Jones wrote:
> > cqspi_setup_flash() uses the chip select taken from each flash child
> > node's reg property to index the fixed-size cqspi->f_pdata[] array,
> > which has CQSPI_MAX_CHIPSELECT entries.
> >
> > The range check now compares the chip select against num_chipselect,
> > which comes straight from the num-cs property and is never clamped to
> > CQSPI_MAX_CHIPSELECT. A device tree which specifies num-cs greater than
> > CQSPI_MAX_CHIPSELECT together with a flash node at a correspondingly
> > high reg value therefore causes writes beyond the end of f_pdata[].
> >
> > Reject chip selects which do not fit in f_pdata[] as well as those which
> > exceed num-cs. While at it, store the chip select in a u32, matching
> > of_property_read_u32(), so that values with the top bit set cannot
> > become negative and slip past the bounds checks.
>
> This commit message was hard to read! Can we do better?
> The issue at hand is super simple.
>
> Repeating the last sentence:
>
> > While at it, store the chip select in a u32, matching
> > of_property_read_u32(), so that values with the top bit set cannot
> > become negative and slip past the bounds checks.
>
> Come on! 2147483648 chip selects?
Fair point!
Since cqspi->num_chipselect is already u32, C's unsigned promotion meant
a negative int would only have slipped past if num-cs itself also had
BIT(31) set. Matching the u32 * expected by of_property_read_u32() is
reason enough on its own without the dramatic justification. =;-D
Will fix.
> > Fixes: 0d62c64a8e48 ("spi: cadence-qspi: assert each subnode flash CS is valid")
> > Closes: https://sashiko.dev/#/bug/linux-cd463fc8-1b94-4bcf-8d06-fae21b88894c
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Lee Jones <lee@kernel.org>
>
> Is this worthy of backporting to all stable releases? It is a indeed
> a bug fix but which can only occur with a broken DT, probably during
> development. It sounds like a lot of churn.
Fine by me. Will be dropped in v2.
> > ---
> > drivers/spi/spi-cadence-quadspi.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
> > index 844df97111d7..fbb917c104b0 100644
> > --- a/drivers/spi/spi-cadence-quadspi.c
> > +++ b/drivers/spi/spi-cadence-quadspi.c
> > @@ -1751,7 +1751,8 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
> > struct platform_device *pdev = cqspi->pdev;
> > struct device *dev = &pdev->dev;
> > struct cqspi_flash_pdata *f_pdata;
> > - int ret, cs, max_cs = -1;
> > + int ret, max_cs = -1;
> > + u32 cs;
> >
> > /* Get flash device data */
> > for_each_available_child_of_node_scoped(dev->of_node, np) {
> > @@ -1761,8 +1762,9 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
> > return ret;
> > }
> >
> > - if (cs >= cqspi->num_chipselect) {
> > - dev_err(dev, "Chip select %d out of range.\n", cs);
> > + if (cs >= cqspi->num_chipselect ||
> > + cs >= CQSPI_MAX_CHIPSELECT) {
> > + dev_err(dev, "Chip select %u out of range.\n", cs);
> > return -EINVAL;
> > }
>
> OK this does fix the bug. Here is another proposal though:
> ensure at probe that cqspi->num_chipselect <= CQSPI_MAX_CHIPSELECT.
One slight hesitation with this.
In cqspi_of_get_pdata(), CQSPI_MAX_CHIPSELECT used to be 16 prior to:
7cc3522aedb5 ("spi: cadence-qspi: set maximum chip-select to 4")
... and cqspi_setup_flash() overwrites cqspi->num_chipselect with max_cs
+ 1 at the end anyway.
Thus if an older or out-of-tree DTB (e.g. with cdns,is-decoded-cs) still
has `num-cs = <16>` while only populating flash@0, failing probe in
cqspi_of_get_pdata() would break a working board, whereas clamping
num_chipselect or checking cs against CQSPI_MAX_CHIPSELECT only rejects
child nodes that would actually overflow f_pdata[].
That said, no in-tree DTS hits this, so if you prefer rejecting
(cqspi->num_chipselect > CQSPI_MAX_CHIPSELECT) or clamping it, let me
know and I will happily make it so.
--
Lee Jones
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size
2026-11-19 14:33 ` Lee Jones
@ 2026-11-19 14:55 ` Théo Lebrun
0 siblings, 0 replies; 12+ messages in thread
From: Théo Lebrun @ 2026-11-19 14:55 UTC (permalink / raw)
To: Lee Jones
Cc: Mark Brown, Foon Tan, Graham Moore, Murugan R,
Vignesh Raghavendra, Pratyush Yadav, Dhruva Gole, linux-spi,
linux-kernel, Miquèl Raynal, Thomas Petazzoni, stable
On Thu Nov 19, 2026 at 3:33 PM CET, Lee Jones wrote:
> On Thu, 19 Nov 2026, Théo Lebrun wrote:
>> On Thu Nov 19, 2026 at 10:17 AM CET, Lee Jones wrote:
>> > @@ -1761,8 +1762,9 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
>> > - if (cs >= cqspi->num_chipselect) {
>> > - dev_err(dev, "Chip select %d out of range.\n", cs);
>> > + if (cs >= cqspi->num_chipselect ||
>> > + cs >= CQSPI_MAX_CHIPSELECT) {
>> > + dev_err(dev, "Chip select %u out of range.\n", cs);
>> > return -EINVAL;
>> > }
>>
>> OK this does fix the bug. Here is another proposal though:
>> ensure at probe that cqspi->num_chipselect <= CQSPI_MAX_CHIPSELECT.
>
> One slight hesitation with this.
>
> In cqspi_of_get_pdata(), CQSPI_MAX_CHIPSELECT used to be 16 prior to:
>
> 7cc3522aedb5 ("spi: cadence-qspi: set maximum chip-select to 4")
>
> ... and cqspi_setup_flash() overwrites cqspi->num_chipselect with max_cs
> + 1 at the end anyway.
>
> Thus if an older or out-of-tree DTB (e.g. with cdns,is-decoded-cs) still
> has `num-cs = <16>` while only populating flash@0, failing probe in
> cqspi_of_get_pdata() would break a working board, whereas clamping
> num_chipselect or checking cs against CQSPI_MAX_CHIPSELECT only rejects
> child nodes that would actually overflow f_pdata[].
>
> That said, no in-tree DTS hits this, so if you prefer rejecting
> (cqspi->num_chipselect > CQSPI_MAX_CHIPSELECT) or clamping it, let me
> know and I will happily make it so.
I still prefer the clamping or erroring from probe. A devicetree (ie
hardware description) which tells us this controller has 16 CS has, is
and will always be wrong. I don't see why we'd want to bother with this
edge-case.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem()
[not found] <20261119091810.3440619-1-lee@kernel.org>
` (5 preceding siblings ...)
2026-11-19 9:17 ` [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 9:17 ` [PATCH 09/10] spi: cadence-xspi: Advance tx pointer between Marvell b0 chunks Lee Jones
2026-11-19 9:17 ` [PATCH 10/10] spi: cadence-xspi: Skip tail read for qword-aligned Marvell b0 receives Lee Jones
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 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>
---
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.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 09/10] spi: cadence-xspi: Advance tx pointer between Marvell b0 chunks
[not found] <20261119091810.3440619-1-lee@kernel.org>
` (6 preceding siblings ...)
2026-11-19 9:17 ` [PATCH 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem() Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
2026-11-19 9:17 ` [PATCH 10/10] spi: cadence-xspi: Skip tail read for qword-aligned Marvell b0 receives Lee Jones
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Jisheng Zhang, Konrad Kociolek, Jayshri Pawar,
Parshuram Thombare, Witold Sadowski, linux-spi, linux-kernel
Cc: stable
cdns_xspi_transfer_one_message_b0() splits transfers which are larger
than MRVL_XFER_MAX_LEN into chunks, but never advances txd between
them. For every chunk after the first, the leading byte is sent from
txd[0] again, and a short trailing chunk retransmits the start of the
buffer instead of its tail. The out_buffer pointer used for the rest
of each chunk is advanced correctly, so the data on the bus ends up
inconsistent.
Advance txd by the size of each chunk when the transfer carries TX data.
TX-less transfers continue to use the zeroed scratch buffer, which is
only ever as large as a single chunk.
Fixes: 931e389ded0f ("spi: cadence: Add Marvell xfer operation support")
Closes: https://sashiko.dev/#/bug/linux-e2ba3b72-ead8-4562-bdb2-4992253c59b4
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-cadence-xspi.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index c4fcbf5ae091..4c9af6146a5d 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -1319,6 +1319,8 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,
cdns_xspi->current_xfer_qword %= MRVL_XFER_QWORD_COUNT;
}
cs_change = t->cs_change;
+ if (t->tx_buf)
+ txd += current_transfer_len;
t->len -= current_transfer_len;
}
spi_transfer_delay_exec(t);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 10/10] spi: cadence-xspi: Skip tail read for qword-aligned Marvell b0 receives
[not found] <20261119091810.3440619-1-lee@kernel.org>
` (7 preceding siblings ...)
2026-11-19 9:17 ` [PATCH 09/10] spi: cadence-xspi: Advance tx pointer between Marvell b0 chunks Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
8 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee, Mark Brown, Jisheng Zhang, Konrad Kociolek, Jayshri Pawar,
Parshuram Thombare, Witold Sadowski, linux-spi, linux-kernel
Cc: stable
In cdns_xspi_transfer_one_message_b0() the receive path reads len / 8
full qwords and then always calls cdns_xspi_finish_read() to collect
the remaining bytes. cdns_xspi_finish_read() unconditionally advances
current_xfer_qword, even when there are no remaining bytes to read.
The TX-only path only accounts for an extra qword when the length is
not a multiple of 8, so for qword-aligned receives the read index runs
one qword ahead and later chunks and transfers in the same message read
the wrong READ_DATA registers.
Only call cdns_xspi_finish_read() when there is a partial qword left to
read, matching the accounting used by the TX-only path.
Fixes: 931e389ded0f ("spi: cadence: Add Marvell xfer operation support")
Closes: https://sashiko.dev/#/bug/linux-13cf6f1e-c300-4fa1-9cd4-08a48ec4f4b9
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-cadence-xspi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index 4c9af6146a5d..bd0fdbbd4060 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -1309,7 +1309,9 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,
for (j = 0; j < current_transfer_len / 8; j++)
marvell_xspi_read_single_qword(cdns_xspi, &rxd);
- cdns_xspi_finish_read(cdns_xspi, &rxd, current_transfer_len);
+ if (current_transfer_len % MRVL_XFER_QWORD_BYTECOUNT)
+ cdns_xspi_finish_read(cdns_xspi, &rxd,
+ current_transfer_len);
} else {
cdns_xspi->current_xfer_qword += current_transfer_len /
MRVL_XFER_QWORD_BYTECOUNT;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread