linux_dsm_epyc7002/include/linux/spi
Lukas Wunner 5e844cc37a
spi: Introduce device-managed SPI controller allocation
SPI driver probing currently comprises two steps, whereas removal
comprises only one step:

    spi_alloc_master()
    spi_register_controller()

    spi_unregister_controller()

That's because spi_unregister_controller() calls device_unregister()
instead of device_del(), thereby releasing the reference on the
spi_controller which was obtained by spi_alloc_master().

An SPI driver's private data is contained in the same memory allocation
as the spi_controller struct.  Thus, once spi_unregister_controller()
has been called, the private data is inaccessible.  But some drivers
need to access it after spi_unregister_controller() to perform further
teardown steps.

Introduce devm_spi_alloc_master() and devm_spi_alloc_slave(), which
release a reference on the spi_controller struct only after the driver
has unbound, thereby keeping the memory allocation accessible.  Change
spi_unregister_controller() to not release a reference if the
spi_controller was allocated by one of these new devm functions.

The present commit is small enough to be backportable to stable.
It allows fixing drivers which use the private data in their ->remove()
hook after it's been freed.  It also allows fixing drivers which neglect
to release a reference on the spi_controller in the probe error path.

Long-term, most SPI drivers shall be moved over to the devm functions
introduced herein.  The few that can't shall be changed in a treewide
commit to explicitly release the last reference on the controller.
That commit shall amend spi_unregister_controller() to no longer release
a reference, thereby completing the migration.

As a result, the behaviour will be less surprising and more consistent
with subsystems such as IIO, which also includes the private data in the
allocation of the generic iio_dev struct, but calls device_del() in
iio_device_unregister().

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: https://lore.kernel.org/r/272bae2ef08abd21388c98e23729886663d19192.1605121038.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-12 15:05:34 +00:00
..
ad7877.h
ads7846.h
altera.h spi: altera: add platform data for slave information. 2020-06-15 23:36:03 +01:00
at73c213.h
at86rf230.h
cc2520.h
corgi_lcd.h
ds1305.h
eeprom.h eeprom: at25: allow page sizes greater than 16 bit 2020-08-28 12:08:08 +02:00
flash.h
ifx_modem.h
libertas_spi.h
lms283gf05.h
max7301.h
mc33880.h
mmc_spi.h
mxs-spi.h
pxa2xx_spi.h
rspi.h
s3c24xx-fiq.h ARM: s3c24xx: move spi fiq handler into platform 2020-08-19 21:45:38 +02:00
s3c24xx.h ARM: s3c24xx: spi: avoid hardcoding fiq number in driver 2020-08-20 17:43:45 +02:00
sh_hspi.h
sh_msiof.h
spi_bitbang.h
spi_gpio.h
spi_oc_tiny.h
spi-fsl-dspi.h
spi-mem.h spi: spi-mem: allow specifying a command's extension 2020-07-14 17:29:38 +01:00
spi.h spi: Introduce device-managed SPI controller allocation 2020-11-12 15:05:34 +00:00
tdo24m.h
tle62x0.h
xilinx_spi.h