* [PATCH 00/10] spi: Fix data corruption, uninitialised data leaks and bounds checks
@ 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
0 siblings, 1 reply; 2+ messages in thread
From: Lee Jones @ 2026-11-19 9:17 UTC (permalink / raw)
To: lee
Cc: linux-kernel, 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, Théo Lebrun,
Tomoya MORINAGA, Vignesh Raghavendra, Weibin Liu, Witold Sadowski,
Yogesh Gaur
These issues were reported by Sashiko.
The series is based on spi/for-7.5, since patch 5 relies on the
following commit, which is not yet in Linus's tree:
3515e312e096 ("spi: topcliff-pch: clamp DMA bpw_len by bytes not words")
Witold, patch 10 is derived from the TX-only accounting in the Marvell
b0 path, so confirmation that it matches the hardware's READ_DATA
behaviour would be appreciated.
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: "Théo Lebrun" <theo.lebrun@bootlin.com>
Cc: Tomoya MORINAGA <tomoya.rohm@gmail.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Weibin Liu <liuwb@xiaopeng.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: Bound chip select against f_pdata array size
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 | 8 +++++---
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, 52 insertions(+), 25 deletions(-)
base-commit: 9b2d7c8736a6fd27ceda93bd67529758c139e24f
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device
2026-11-19 9:17 [PATCH 00/10] spi: Fix data corruption, uninitialised data leaks and bounds checks Lee Jones
@ 2026-11-19 9:17 ` Lee Jones
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2026-11-19 9:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 9:17 [PATCH 00/10] spi: Fix data corruption, uninitialised data leaks and bounds checks Lee Jones
2026-11-19 9:17 ` [PATCH 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox