linux/drivers/staging
Johan Hovold 16ba3b0c66
spi: fix controller registration API inconsistency
The SPI controller API is asymmetric in that a controller is allocated
and registered in two step, while it is freed as part of deregistration.
[1]

This is especially unfortunate as any driver data is freed along with
the controller, something which has lead to use-after-free bugs during
deregistration when drivers tear down resources after deregistering the
controller (or tear down resources that may still be in use before
deregistering the controller in an attempt to work around the API).

To reduce the risk of such bugs being introduced a device managed
allocation interface was added, but this arguably made things even less
consistent as now whether the controller gets freed as part of
deregistration depends on how it was allocated. [2][3]

With most drivers converted to use managed allocation in preparation for
fixing the API, the remaining 16 drivers can be converted in one
tree-wide change. Ten of those drivers use the bitbang interface and can
be converted by simply removing the extra reference already taken by
spi_bitbang_start() (and updating the two bitbang drivers that use
managed allocation). [4]

Fix the API inconsistency by no longer dropping a reference when
deregistering non-devres allocated controllers.

[1] 68b892f1fd ("spi: document odd controller reference handling")
[2] 5e844cc37a ("spi: Introduce device-managed SPI controller allocation")
[3] 3f174274d2 ("spi: fix misleading controller deregistration kernel-doc")
[4] 702a4879ec ("spi: bitbang: Let spi_bitbang_start() take a reference to master")

Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260521073816.766596-1-johan@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
History 2026-05-21 12:25:55 +01:00
..
axis-fifo staging: axis-fifo: refactor device tree parsing 2026-02-23 15:45:31 +01:00
fbtft staging: fbtft: Update RA8875 Kconfig help description 2026-03-09 17:46:57 +01:00
greybus spi: fix controller registration API inconsistency 2026-05-21 12:25:55 +01:00
iio staging: iio: ad9834: use sysfs_emit() and simplify show functions 2026-03-21 13:16:07 +00:00
media staging: media: ipu7: Update TODO 2026-03-26 14:33:07 +01:00
most staging: most: dim2: replace BUG_ON() in poison_channel() 2026-03-31 10:46:39 +02:00
nvec staging: nvec: fix block comment style in nvec_interrupt() 2026-02-24 10:11:42 -08:00
octeon staging: octeon: remove BUG() call 2026-03-18 16:48:40 +01:00
rtl8723bs staging: rtl8723bs: os_dep: avoid NULL pointer dereference in rtw_cbuf_alloc 2026-05-04 11:36:47 +02:00
sm750fb staging: sm750fb: fix division by zero in ps_to_hz() 2026-03-31 10:33:21 +02:00
vc04_services Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
vme_user staging: vme_user: fix root device leak on init failure 2026-05-04 11:29:53 +02:00
Kconfig staging: gpib: Destage gpib 2025-11-24 17:52:11 +01:00
Makefile staging: gpib: Destage gpib 2025-11-24 17:52:11 +01:00