Commit Graph
8420 Commits
Author SHA1 Message Date
Santhosh Kumar K 79378db6a8 spi: spi-mem: avoid mutating op template in spi_mem_supports_op()
spi_mem_supports_op() accepts a const struct spi_mem_op pointer but
casts away const internally to call spi_mem_adjust_op_freq(). This
mutates the caller's op template, which causes stale max_freq values
when callers reuse persistent templates - subsequent calls won't
re-apply the device frequency cap since spi_mem_adjust_op_freq()
skips non-zero values.

Fix by operating on a stack-local copy instead.

Fixes: a4f8e70d75 ("spi: spi-mem: add spi_mem_adjust_op_freq() in spi_mem_supports_op()")
Cc: Tianyu Xu <[email protected]>
Cc: [email protected]
Signed-off-by: Santhosh Kumar K <[email protected]>
Reviewed-by: Miquel Raynal <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-28 13:49:00 +01:00
Linus Torvalds e216d85eaf Merge tag 'spi-fix-v7.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown:
 "Another batch of driver fixes from Johan fixing error handling paths,
  plus another from Felix. We also have a new device ID added in the DT
  bindings for SpacemiT K3"

* tag 'spi-fix-v7.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi:
  spi: dt-bindings: fsl-qspi: support SpacemiT K3
  spi: ti-qspi: fix use-after-free after DMA setup failure
  spi: sprd: fix error pointer deref after DMA setup failure
  spi: qup: fix error pointer deref after DMA setup failure
  spi: mtk-snfi: Fix resource leak in mtk_snand_read_page_cache()
  spi: ep93xx: fix error pointer deref after DMA setup failure
2026-05-22 13:19:41 -07:00
Johan Hovold ea6ec3343e spi: ti-qspi: fix use-after-free after DMA setup failure
The driver falls back to PIO mode if DMA setup fails during probe.

Make sure to clear the DMA channel pointer also if buffer allocation
fails to avoid passing a pointer to the released channel to the DMA
engine (or trying to free the channel a second time on late probe errors
or driver unbind).

This issue was flagged by Sashiko when reviewing a devres allocation
conversion patch.

Fixes: c687c46e9e ("spi: spi-ti-qspi: Use bounce buffer if read buffer is not DMA'ble")
Link: https://sashiko.dev/#/patchset/20260505072909.618363-1-johan%40kernel.org?part=17
Cc: [email protected]	# 4.12
Cc: Vignesh R <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-18 17:40:51 +01:00
Johan Hovold 3d67fffb74 spi: sprd: fix error pointer deref after DMA setup failure
The driver falls back to PIO mode if DMA setup fails during probe.

Make sure to check the dma.enabled flag before trying to release the DMA
channels also on late probe errors to avoid dereferencing an error
pointer (or attempting to release a channel a second time).

This issue was flagged by Sashiko when reviewing a devres allocation
conversion patch.

Fixes: 386119bc7b ("spi: sprd: spi: sprd: Add DMA mode support")
Link: https://sashiko.dev/#/patchset/20260505072909.618363-1-johan%40kernel.org?part=10
Cc: [email protected]	# 5.1
Cc: Lanqing Liu <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-18 17:40:30 +01:00
Johan Hovold a7e8f3efd5 spi: qup: fix error pointer deref after DMA setup failure
The driver falls back to PIO mode if DMA setup fails during probe.

Make sure to the clear the DMA channel pointers on setup failure to
avoid dereferencing an error pointer (or attempting to release a channel
a second time) on later probe errors or driver unbind.

This issue was flagged by Sashiko when reviewing a devres allocation
conversion patch.

Fixes: 612762e82a ("spi: qup: Add DMA capabilities")
Link: https://sashiko.dev/#/patchset/20260505072909.618363-1-johan%40kernel.org?part=4
Cc: [email protected]	# 4.1
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-18 17:36:26 +01:00
Felix Gu 496ba79b94 spi: mtk-snfi: Fix resource leak in mtk_snand_read_page_cache()
When DMA read times out in mtk_snand_read_page_cache(), the original code
erroneously jumped to cleanup label which skips DMA unmapping and ECC
disable, causing a resource leak.

Fixes: 764f1b7481 ("spi: add driver for MTK SPI NAND Flash Interface")
Signed-off-by: Felix Gu <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-16 11:27:08 +09:00
Johan Hovold 5e121a8166 spi: ep93xx: fix error pointer deref after DMA setup failure
The driver falls back to PIO mode if DMA setup fails during probe.

Make sure to the clear the DMA channel pointers on setup failure to
avoid dereferencing an error pointer on later probe errors or driver
unbind.

This issue was flagged by Sashiko when reviewing a devres allocation
conversion patch.

Fixes: e79e7c2df6 ("spi: ep93xx: add DT support for Cirrus EP93xx")
Link: https://sashiko.dev/#/patchset/20260429091333.165363-1-johan%40kernel.org?part=10
Cc: [email protected]	# 6.12
Cc: Nikita Shubin <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Acked-by: Nikita Shubin <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-12 21:49:06 +09:00
Krishnamoorthi M 422bd00b71 spi: amd: Set correct bus number in ACPI probe path
On platforms where the HID2 SPI controller (AMDI0063) is enumerated via
ACPI instead of PCI, amd_spi_probe() unconditionally sets bus_num to 0,
while the PCI probe path assigns bus_num 2 for HID2 controller.

Align the ACPI probe path to use the same bus number so that userspace
and SPI client drivers see a consistent bus assignment regardless of the
enumeration method.

Fixes: b644c27766 ("spi: spi_amd: Add PCI-based driver for AMD HID2 SPI controller")
Cc: [email protected] # v6.16+
Signed-off-by: Krishnamoorthi M <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-11 09:29:12 +09:00
Jiawei Liu 4bacec2317 spi: ch341: correct company name in MODULE_DESCRIPTION
The company name "QiHeng Electronics" is incorrect.
The correct legal name is "Nanjing Qinheng Microelectronics Co., Ltd.".

Update the module description accordingly.

Signed-off-by: Jiawei Liu <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-06 23:09:33 +09:00
Mark Brown 4b50e6cc2a spi: microchip core-qspi gpio-cs fixes + cleanup
Conor Dooley <[email protected]> says:

v3 with the review comment about the core handing CS_HIGH dealt with.
I noticed that in the same function there was a "raw" BIT(1), which I
replaced with a macro that the patch was already adding for use in the
setup function...
2026-05-04 22:23:04 +09:00
Conor Dooley 0b2eb1f847 spi: microchip-core-qspi: remove some inline markings
Remove inline markings from a number of functions that are called as
part of mem ops callbacks. None of them are either particularly trivial
or sensitive to overhead of a function call. Just let the compiler
decide what to do with them.

Signed-off-by: Conor Dooley <[email protected]>
Link: https://patch.msgid.link/20260430-serpent-stimulate-59fb860ef429@spud
Signed-off-by: Mark Brown <[email protected]>
2026-05-04 22:23:02 +09:00
Conor Dooley eb56deaabf spi: microchip-core-qspi: don't attempt to transmit during emulated read-only dual/quad operations
The core will deal with reads by creating clock cycles itself, there's
no need to generate clock cycles by transmitting garbage data at the
driver level. Further, transmitting garbage data just bricks the transfer
since QSPI doesn't have a dedicated master-out line like MOSI in regular
SPI. I'm not entirely sure if the transfer is bricked because of the
garbage data being transmitted on the bus or because the core loses
track of whether it is supposed to be sending or receiving data.

Fixes: 8f9cf02c88 ("spi: microchip-core-qspi: Add regular transfers")
CC: [email protected]
Signed-off-by: Conor Dooley <[email protected]>
Link: https://patch.msgid.link/20260430-freezing-saloon-95b1f3d9dad0@spud
Signed-off-by: Mark Brown <[email protected]>
2026-05-04 22:23:01 +09:00
Conor Dooley 7672749e14 spi: microchip-core-qspi: control built-in cs manually
The coreQSPI IP supports only a single chip select, which is
automagically operated by the hardware - set low when the transmit
buffer first gets written to and set high when the number of bytes
written to the TOTALBYTES field of the FRAMES register have been sent on
the bus. Additional devices must use GPIOs for their chip selects.
It was reported to me that if there are two devices attached to this
QSPI controller that the in-built chip select is set low while linux
tries to access the device attached to the GPIO.

This went undetected as the boards that connected multiple devices to
the SPI controller all exclusively used GPIOs for chip selects, not
relying on the built-in chip select at all. It turns out that this was
because the built-in chip select, when controlled automagically, is set
low when active and high when inactive, thereby ruling out its use for
active-high devices or devices that need to transmit with the chip
select disabled.

Modify the driver so that it controls chip select directly, retaining
the behaviour for mem_ops of setting the chip select active for the
entire duration of the transfer in the exec_op callback. For regular
transfers, implement the set_cs callback for the core to use.

As part of this, the existing setup callback, mchp_coreqspi_setup_op(),
is removed. Modifying the CLKIDLE field is not safe to do during
operation when there are multiple devices, so this code is removed
entirely. Setting the MASTER and ENABLE fields is something that can be
done once at probe, it doesn't need to be re-run for each device.
Instead the new setup callback sets the built-in chip select to its
inactive state for active-low devices, as the reset value of the chip
select in software controlled mode is low.

Fixes: 8f9cf02c88 ("spi: microchip-core-qspi: Add regular transfers")
Fixes: 8596124c4c ("spi: microchip-core-qspi: Add support for microchip fpga qspi controllers")
CC: [email protected]
Signed-off-by: Conor Dooley <[email protected]>
Link: https://patch.msgid.link/20260430-hamstring-busload-f941d0347b5e@spud
Signed-off-by: Mark Brown <[email protected]>
2026-05-04 22:23:00 +09:00
John Madieu 894e04b711 spi: imx: Propagate prepare_transfer() error from spi_imx_setupxfer()
spi_imx_setupxfer() calls the per-variant prepare_transfer()
callback and returns 0 unconditionally:

	spi_imx->devtype_data->prepare_transfer(spi_imx, spi, t);

	return 0;

mx51_ecspi_prepare_transfer() can return -EINVAL when the requested
word_delay does not fit in MX51_ECSPI_PERIOD_MASK. The error is
detected after a partial set of register writes (CTRL: BL, clkdiv,
SMC), so the controller is left in a partially-configured state and
the transfer is then submitted as if setup succeeded.

Propagate the return value. The other variants' prepare_transfer
callbacks all return 0, so this is a no-op for them.

Fixes: a3bb4e663d ("spi: imx: support word delay")
Signed-off-by: John Madieu <[email protected]>
Reviewed-by: Frank Li <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-04 22:22:16 +09:00
John Madieu f5b5548255 spi: imx: Fix UAF on package-1 prepare failure in spi_imx_dma_data_prepare()
When transfer->len exceeds MX51_ECSPI_CTRL_MAX_BURST and is not a
multiple of it, spi_imx_dma_data_prepare() splits the transfer into
two DMA packages. If preparing the second package fails:

	ret = spi_imx_dma_tx_data_handle(spi_imx, &spi_imx->dma_data[1],
					 transfer->tx_buf + spi_imx->dma_data[0].data_len,
					 false);
	if (ret) {
		kfree(spi_imx->dma_data[0].dma_tx_buf);
		kfree(spi_imx->dma_data[0].dma_rx_buf);
		kfree(spi_imx->dma_data);
	}
	}

	return 0;

the function frees the package-0 buffers and the dma_data array,
then falls through to `return 0`, telling the caller the prepare
succeeded. The caller then dereferences the freed dma_data array,
producing a use-after-free.

Return the error from the failure path so the caller takes its
existing failure branch.

Fixes: faa8e404ad ("spi: imx: support dynamic burst length for ECSPI DMA mode")
Signed-off-by: John Madieu <[email protected]>
Reviewed-by: Frank Li <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-04 22:22:15 +09:00
John Madieu 24e0fd8b85 spi: imx: Fix precedence bug in spi_imx_dma_max_wml_find()
The watermark search in spi_imx_dma_max_wml_find() reads:

	if (!dma_data->dma_len % (i * bytes_per_word))
		break;

The unary ! binds tighter than %, so this parses as:

	if ((!dma_data->dma_len) % (i * bytes_per_word))
		break;

!dma_data->dma_len is 0 or 1, and `0 % x == 0` for any x; `1 % x` is
0 unless x == 1. The condition is therefore false in every case
except dma_len != 0 with i * bytes_per_word == 1, i.e. i == 1 and
bytes_per_word == 1.

The loop almost always falls through to its end, leaving i == 0,
which the post-loop fallback rewrites to 1:

	if (i == 0)
		i = 1;

So spi_imx->wml ends up at 1 for essentially every DMA transfer,
defeating the entire purpose of the function. The DMA engine then
requests service after every single FIFO word instead of using
multi-word bursts, hurting throughput on every DMA-capable variant.

Add the missing parentheses so the modulo is computed first, then
negated:

	if (!(dma_data->dma_len % (i * bytes_per_word)))
		break;

Fixes: faa8e404ad ("spi: imx: support dynamic burst length for ECSPI DMA mode")
Signed-off-by: John Madieu <[email protected]>
Reviewed-by: Frank Li <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-05-04 22:22:14 +09:00
Mark Brown 8c0f9cd1df spi: cadence: Probe and unbind fixes
Several fixes from Johan for issues with unbind and error handling in
probe.
2026-05-01 10:14:39 +09:00
Mark Brown 4f12ee0a4d spi: cadence-quadspi: Probe and unbind fixes
Several fixes from Johan for probe failure and unbind issues in the
cadence-quadspi driver.
2026-05-01 10:12:57 +09:00
Felix Gu 8d0189c1ea spi: amlogic-spisg: initialize completion before requesting IRQ
Move init_completion(&spisg->completion) to before devm_request_irq()
to avoid a potential race condition where an interrupt could fire
before the completion structure is initialized.

Fixes: cef9991e04 ("spi: Add Amlogic SPISG driver")
Signed-off-by: Felix Gu <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-28 09:57:15 +09:00
Felix Gu f5c6a272b6 spi: axiado: replace usleep_range() with udelay() in IRQ path
ax_spi_fill_tx_fifo() can be called from ax_spi_irq() which is a hard
irq handler. Replace usleep_range(10, 10) with udelay(10) in atomic
context.

Fixes: e75a6b00ad ("spi: axiado: Add driver for Axiado SPI DB controller")
Signed-off-by: Felix Gu <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-28 08:35:59 +09:00
Johan Hovold 5e8bb0cc72 spi: cadence-quadspi: fix runtime pm and clock imbalance on unbind
Make sure to balance the runtime PM usage count before returning on
probe failure (to allow the controller to suspend after a probe
deferral) and to only drop the usage count on driver unbind to avoid a
clock disable imbalance.

Also restore the autosuspend setting.

Fixes: 0578a6dbfe ("spi: spi-cadence-quadspi: add runtime pm support")
Cc: [email protected]	# 6.7
Cc: Dhruva Gole <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 08:26:37 +09:00
Johan Hovold 233db2cb14 spi: cadence-quadspi: fix unclocked access on unbind
Make sure that the controller is runtime resumed before disabling it
during driver unbind to avoid an unclocked register access.

This issue was flagged by Sashiko when reviewing a controller
deregistration fix.

Fixes: 0578a6dbfe ("spi: spi-cadence-quadspi: add runtime pm support")
Cc: [email protected]	# 6.7
Cc: Dhruva Gole <[email protected]>
Link: https://sashiko.dev/#/patchset/20260414134319.978196-1-johan%40kernel.org?part=2
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 08:26:36 +09:00
Johan Hovold cba53fe20c spi: cadence-quadspi: fix clock imbalance on probe failure
Drop the bogus runtime PM get on probe failures that was never needed
and that leaks a usage count reference while preventing the clocks from
being disabled (as runtime PM has not yet been enabled).

Fixes: 1889dd2081 ("spi: cadence-quadspi: Fix clock disable on probe failure path")
Cc: [email protected]	# 6.19
Cc: Anurag Dutta <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 08:26:35 +09:00
Johan Hovold 5ff4d5d1af spi: cadence-quadspi: fix runtime pm disable imbalance on probe failure
A recent attempt to fix the probe error handling introduced a runtime PM
disable depth imbalance by incorrectly disabling runtime PM on early
failures (e.g. probe deferral).

Fixes: f18c8cfa4f ("spi: cadence-qspi: Fix probe error path and remove")
Cc: [email protected]	# 7.0
Cc: Miquel Raynal (Schneider Electric) <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 08:26:35 +09:00
Johan Hovold ecea4f0e9d spi: cadence: fix clock imbalance on probe failure
Make sure that the controller is active before disabling clocks on probe
failure to avoid unbalanced clock disable.

Also drop the usage count before returning (so that the controller can
be suspended after a probe deferral) and restore the autosuspend
setting.

Fixes: d36ccd9f7e ("spi: cadence: Runtime pm adaptation")
Cc: [email protected]	# 4.7
Cc: Shubhrajyoti Datta <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 08:25:49 +09:00
Johan Hovold 5b1689a41f spi: cadence: fix unclocked access on unbind
Make sure that the controller is runtime resumed before disabling it
during driver unbind to avoid unclocked register access and unbalanced
clock disable.

Also restore the autosuspend setting.

This issue was flagged by Sashiko when reviewing a controller
deregistration fix.

Fixes: d36ccd9f7e ("spi: cadence: Runtime pm adaptation")
Cc: [email protected]	# 4.7
Cc: Shubhrajyoti Datta <[email protected]>
Link: https://sashiko.dev/#/patchset/20260414134319.978196-1-johan%40kernel.org?part=1
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 08:25:48 +09:00
John Madieu 7643978722 spi: rockchip: Drop unused and broken CR0 macros
Two CTRLR0 macros are defined but never referenced, and both are wrong:

 - CR0_XFM_MASK shifts by SPI_XFM_OFFSET, which does not exist anywhere
   in the tree. The intended symbol is CR0_XFM_OFFSET.

 - CR0_MTM_OFFSET is defined as 0x21, i.e. bit 33 of a 32-bit register.
   The value is meaningless and the macro is unused.

Drop both. They can be re-introduced correctly when an actual user
appears.

Signed-off-by: John Madieu <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 06:57:20 +09:00
John Madieu b4683a239a spi: rockchip: Read ISR, not IMR, to detect cs-inactive IRQ
rockchip_spi_isr() decides whether the current interrupt was the
cs-inactive event by reading IMR:

	if (rs->cs_inactive &&
	    readl_relaxed(rs->regs + ROCKCHIP_SPI_IMR) & INT_CS_INACTIVE)
		ctlr->target_abort(ctlr);

IMR is the interrupt mask register: it tells which sources are enabled,
not which one fired. In the PIO path, rockchip_spi_prepare_irq() enables
both INT_RF_FULL and INT_CS_INACTIVE in IMR when rs->cs_inactive is true:

	if (rs->cs_inactive)
		writel_relaxed(INT_RF_FULL | INT_CS_INACTIVE,
			       rs->regs + ROCKCHIP_SPI_IMR);

so the IMR check is always true once cs_inactive is enabled, and every
PIO interrupt - including normal RF_FULL completions - is dispatched to
ctlr->target_abort(), aborting the transfer. The bug is reachable on
ROCKCHIP_SPI_VER2_TYPE2 in target mode with a DMA-capable controller
when the transfer is short enough to fall back to PIO
(rockchip_spi_can_dma() returns false below fifo_len).

Read ISR (which is RISR masked by IMR) so the check actually reflects
which interrupt fired, and parenthesise the expression for clarity while
at it.

Fixes: 869f2c94db ("spi: rockchip: Stop spi slave dma receiver when cs inactive")
Signed-off-by: John Madieu <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 06:57:20 +09:00
John Madieu 54900126ae spi: rzv2h-rspi: Fix silent failure in clock setup error path
rzv2h_rspi_setup_clock() is declared to return u32 but returns -EINVAL
when no valid clock parameters are found. Cast to u32, -EINVAL becomes
0xffffffea, which is a non-zero value. The caller in
rzv2h_rspi_prepare_message() guards against failure with:

	rspi->freq = rzv2h_rspi_setup_clock(rspi, speed_hz);
	if (!rspi->freq)
		return -EINVAL;

Because 0xffffffea is non-zero, the check is bypassed and the controller
proceeds to program SPBR/SPCMD with stale values, leading to an unknown
bit rate.

Return 0 on the failed-search path, consistent with the existing
clk_set_rate() failure path which already returns 0.

Fixes: 77d931584d ("spi: rzv2h-rspi: make transfer clock rate finding chip-specific")
Signed-off-by: John Madieu <[email protected]>
Reviewed-by: Biju Das <[email protected]>
Reviewed-by: Cosmin Tanislav <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-27 06:45:08 +09:00
Linus Torvalds b2680ba4a2 Merge tag 'spi-fix-v7.1-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown:
 "This is quite a big set of fixes, almost all from Johan Hovold who is
  on an ongoing quest to clean up issues with probe and removal handling
  in drivers.

  There isn't anything too concerning here especially with the
  deregistration stuff which will very rarely get run in production
  systems since this is all platform devices in the SoC on embedded
  hardware, but it's all real issues which should be fixed. There's more
  in flight here.

  We also have a few other minor fixes, one from Felix Gu along the same
  lines as Johan's work and a couple of documentation things"

* tag 'spi-fix-v7.1-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (23 commits)
  spi: fix controller cleanup() documentation
  spi: fix resource leaks on device setup failure
  spi: axiado: clean up probe return value
  spi: axiado: rename probe error labels
  spi: axiado: fix runtime pm imbalance on probe failure
  spi: orion: clean up probe return value
  spi: orion: fix clock imbalance on registration failure
  spi: orion: fix runtime pm leak on unbind
  spi: imx: fix runtime pm leak on probe deferral
  spi: mpc52xx: fix use-after-free on registration failure
  spi: Fix the error description in the `ptp_sts_word_post` comment
  spi: topcliff-pch: fix use-after-free on unbind
  spi: topcliff-pch: fix controller deregistration
  spi: orion: fix controller deregistration
  spi: mxic: fix controller deregistration
  spi: mpc52xx: fix use-after-free on unbind
  spi: mpc52xx: fix controller deregistration
  spi: cadence-quadspi: fix controller deregistration
  spi: cadence: fix controller deregistration
  spi: mtk-snfi: fix memory leak in probe
  ...
2026-04-24 13:16:36 -07:00
Mark Brown 16ab65df5d spi: fix resource leaks on device setup failure
Johan Hovold <[email protected]> says:

Make sure to call controller cleanup() if spi_setup() fails while
registering a device to avoid leaking any resources allocated by
setup().
2026-04-22 15:10:22 +01:00
Johan Hovold db357034f7 spi: fix resource leaks on device setup failure
Make sure to call controller cleanup() if spi_setup() fails while
registering a device to avoid leaking any resources allocated by
setup().

Fixes: c7299fea67 ("spi: Fix spi device unregister flow")
Cc: [email protected]	# 5.13
Cc: Saravana Kannan <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 15:10:17 +01:00
Mark Brown ad50f7bc5a spi: axiado: spi: axiado: fix runtime pm imbalance on probe failure
Johan Hovold <[email protected]> says:

The series fixes some runtime PM related issues in the axiado driver.

Included is also a couple of related cleanups.
2026-04-22 15:05:57 +01:00
Johan Hovold 2b20e67424 spi: axiado: clean up probe return value
Drop the redundant initialisation and return explicit zero on successful
probe to make the code more readable.

Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 15:05:53 +01:00
Johan Hovold 821f0951b2 spi: axiado: rename probe error labels
Rename the probe error labels after what they do.

Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 15:05:52 +01:00
Johan Hovold cde1a784e4 spi: axiado: fix runtime pm imbalance on probe failure
Make sure that the controller is active before disabling clocks on late
probe failure and on driver unbind to avoid a clock disable imbalance.

Also make sure that the usage count is balanced on probe failure (e.g.
probe deferral) so that the controller can be suspended when a driver is
later bound.

Note that the runtime PM state can only be set when runtime PM is
disabled.

Fixes: e75a6b00ad ("spi: axiado: Add driver for Axiado SPI DB controller")
Cc: [email protected]	# 7.0
Cc: Vladimir Moravcevic <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 15:05:51 +01:00
Mark Brown 8370f1bd64 spi: orion: runtime PM fixes
Johan Hovold <[email protected]> says:

This series fixes some runtime PM related issues in the orion driver.

Included is also a related clean up.
2026-04-22 13:49:21 +01:00
Johan Hovold fa5061daff spi: orion: clean up probe return value
Drop the redundant initialisation and return explicit zero on successful
probe to make the code more readable.

Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 13:49:16 +01:00
Johan Hovold 443cde0dc5 spi: orion: fix clock imbalance on registration failure
Make sure that the controller is not runtime suspended before disabling
clocks on probe failure.

Also restore the autosuspend setting.

Fixes: 5c6786945b ("spi: spi-orion: add runtime PM support")
Cc: [email protected]	# 3.17
Cc: Russell King <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 13:49:15 +01:00
Johan Hovold 97b17dd826 spi: orion: fix runtime pm leak on unbind
Make sure to balance the runtime PM usage count on driver unbind so that
the controller can be suspended when a driver is rebound.

Also restore the autosuspend setting.

This issue was flagged by Sashiko when reviewing a controller
deregistration fix.

Fixes: 5c6786945b ("spi: spi-orion: add runtime PM support")
Cc: [email protected]	# 3.17
Cc: Russell King <[email protected]>
Link: https://sashiko.dev/#/patchset/20260414134319.978196-1-johan%40kernel.org?part=6
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 13:49:14 +01:00
Johan Hovold a1d50a37d3 spi: imx: fix runtime pm leak on probe deferral
Make sure to balance the runtime PM usage count before returning on
probe failure (e.g. probe deferral) so that the controller can be
suspended when a driver is later bound.

Fixes: 43b6bf406c ("spi: imx: fix runtime pm support for !CONFIG_PM")
Cc: [email protected]	# 5.10
Cc: Sascha Hauer <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 13:44:20 +01:00
Johan Hovold f62c060272 spi: mpc52xx: fix use-after-free on registration failure
Make sure to disable and free the interrupts in case controller
registration fails to avoid a potential use-after-free and resource
leak.

This issue was flagged by Sashiko when reviewing a controller
deregistration fix.

Fixes: 42bbb70980 ("powerpc/5200: Add mpc5200-spi (non-PSC) device driver")
Cc: [email protected]	# 2.6.33
Cc: Grant Likely <[email protected]>
Link: https://sashiko.dev/#/patchset/20260414134319.978196-1-johan%40kernel.org?part=3
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-22 13:43:09 +01:00
Mark Brown ce76a36223 spi: fix explicit controller deregistration
Johan Hovold <[email protected]> says:

Turns out we have a few drivers that get the tear down ordering wrong
also when not using device managed registration (cf. [1] and [2]).

Fix this to avoid issues like system errors due to unclocked accesses,
NULL-pointer dereferences, hangs or failed I/O during during
deregistration (e.g. when powering down devices).

Johan

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
2026-04-20 12:39:35 +01:00
Johan Hovold 9d72732fe7 spi: topcliff-pch: fix use-after-free on unbind
Give the driver a chance to flush its queue before releasing the DMA
buffers on driver unbind

Fixes: c37f3c2749 ("spi/topcliff_pch: DMA support")
Cc: [email protected]	# 3.1
Cc: Tomoya MORINAGA <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-20 12:39:31 +01:00
Johan Hovold 5d6f477d6f spi: topcliff-pch: fix controller deregistration
Make sure to deregister the controller before disabling and releasing
underlying resources like interrupts and DMA during driver unbind.

Fixes: e8b17b5b3f ("spi/topcliff: Add topcliff platform controller hub (PCH) spi bus driver")
Cc: [email protected]	# 2.6.37
Cc: Masayuki Ohtake <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-20 12:39:30 +01:00
Johan Hovold 220f4f1110 spi: orion: fix controller deregistration
Make sure to deregister the controller before disabling underlying
resources like clocks during driver unbind.

Fixes: 60cadec9da ("spi: new orion_spi driver")
Cc: [email protected]	# 2.6.27
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-20 12:39:29 +01:00
Johan Hovold adbc595e27 spi: mxic: fix controller deregistration
Make sure to deregister the controller before disabling underlying
resources like clocks (via runtime pm) during driver unbind.

Fixes: b942d80b0a ("spi: Add MXIC controller driver")
Cc: [email protected]	# 5.0: cc53711b21
Cc: [email protected]	# 5.0
Cc: Mason Yang <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-20 12:39:28 +01:00
Johan Hovold 706b3dc2ac spi: mpc52xx: fix use-after-free on unbind
The state machine work is scheduled by the interrupt handler and
therefore needs to be cancelled after disabling interrupts to avoid a
potential use-after-free.

Fixes: 984836621a ("spi: mpc52xx: Add cancel_work_sync before module remove")
Cc: [email protected]
Cc: Pei Xiao <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-20 12:39:27 +01:00
Johan Hovold 0f997fdae8 spi: mpc52xx: fix controller deregistration
Make sure to deregister the controller before disabling and releasing
underlying resources like interrupts and gpios during driver unbind.

Fixes: 42bbb70980 ("powerpc/5200: Add mpc5200-spi (non-PSC) device driver")
Fixes: b8d4e2ce60 ("mpc52xx_spi: add gpio chipselect")
Cc: [email protected]	# 2.6.33
Cc: Grant Likely <[email protected]>
Cc: Luotao Fu <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-20 12:39:26 +01:00
Johan Hovold 964ee97937 spi: cadence-quadspi: fix controller deregistration
Make sure to deregister the controller before dropping the reference
count that allows new operations to start to allow SPI drivers to do I/O
during deregistration.

Fixes: 7446284023 ("spi: cadence-quadspi: Implement refcount to handle unbind during busy")
Cc: [email protected]	# 6.17
Cc: Khairul Anuar Romli <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-04-20 12:39:25 +01:00