Files
linux/include/linux
Lukas Wunner 0870525cf9 spi: Introduce device-managed SPI controller allocation
[ Upstream commit 5e844cc37a ]

SPI driver probing currently comprises two steps, whereas removal
comprises only one step:

    spi_alloc_master()
    spi_register_master()

    spi_unregister_master()

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

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

Introduce devm_spi_alloc_master(), which releases a reference on the
spi_master struct only after the driver has unbound, thereby keeping the
memory allocation accessible.  Change spi_unregister_master() to not
release a reference if the spi_master was allocated by the new devm
function.

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_master in the probe error path.

Long-term, most SPI drivers shall be moved over to the devm function
introduced herein.  The few that can't shall be changed in a treewide
commit to explicitly release the last reference on the master.
That commit shall amend spi_unregister_master() 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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-12-11 13:38:00 +01:00
..
2015-10-07 18:08:15 +01:00
2016-07-08 16:23:11 +02:00
2016-08-25 11:26:48 -04:00
2017-10-08 10:26:06 +02:00
2018-04-24 09:34:18 +02:00
2016-09-14 09:18:06 -06:00
2018-02-28 10:18:33 +01:00
2016-06-07 13:41:38 -06:00
2016-05-17 15:48:12 -04:00
2017-05-14 14:00:22 +02:00
2019-11-25 09:53:14 +01:00
2017-07-12 15:01:02 +02:00
2020-09-03 11:21:21 +02:00
2017-08-06 18:59:43 -07:00
2020-04-02 17:20:27 +02:00
2016-07-22 09:07:02 +02:00
2016-09-24 10:48:18 +02:00
2015-11-25 09:22:00 -07:00
2016-02-11 09:59:22 -05:00
2016-10-20 15:51:28 +11:00
2016-09-16 09:34:15 +01:00
2016-09-14 09:18:09 -06:00
2016-05-11 22:37:54 +02:00
2015-06-25 12:06:45 +02:00
2016-01-28 14:19:12 -08:00
2018-10-10 08:53:18 +02:00
2016-03-22 15:36:02 -07:00
2016-08-10 11:23:44 -04:00
2016-03-22 15:36:02 -07:00
2015-07-28 08:50:42 +01:00
2020-04-02 17:20:40 +02:00
2016-01-15 17:56:32 -08:00
2016-09-15 16:49:39 +02:00
2016-09-27 12:33:47 +02:00
2017-08-24 17:12:19 -07:00
2015-06-24 17:49:41 -07:00
2015-07-21 10:39:05 -07:00
2016-07-29 12:17:52 -07:00
2016-04-25 15:09:11 -04:00
2016-02-16 13:04:58 -05:00
2016-10-19 11:36:22 -06:00
2016-05-02 09:00:56 -05:00
2020-11-18 18:26:29 +01:00
2016-02-11 18:35:48 -08:00
2016-03-14 15:43:11 -04:00
2020-03-20 09:07:43 +01:00
2017-08-24 17:12:21 -07:00
2016-10-14 11:36:59 -07:00
2016-07-12 19:25:38 -07:00
2016-09-27 21:52:00 -04:00
2016-09-08 15:01:10 -07:00
2016-03-17 15:09:34 -07:00
2016-07-06 10:51:14 +01:00
2016-03-22 15:36:02 -07:00
2016-07-26 16:19:19 -07:00
2016-09-08 22:15:25 -07:00
2020-04-24 07:58:54 +02:00
2020-04-02 17:20:39 +02:00
2017-08-30 10:21:40 +02:00
2016-08-28 23:44:55 -04:00
2016-05-08 23:46:14 -04:00
2016-10-05 18:23:36 -04:00
2019-04-17 08:36:39 +02:00
2015-06-25 17:00:39 -07:00
2018-11-13 11:17:02 -08:00
2015-10-01 09:57:59 -07:00
2016-07-19 17:43:38 +03:00
2020-12-11 13:38:00 +01:00
2016-05-23 17:04:14 -07:00
2016-04-07 16:53:29 -04:00
2017-04-21 09:31:21 +02:00
2015-11-23 09:44:58 +01:00
2016-07-26 16:19:19 -07:00
2016-05-20 17:58:30 -07:00
2017-12-25 14:23:37 +01:00
2020-04-02 17:20:39 +02:00
2016-09-30 10:54:03 +02:00
2015-12-03 07:24:29 -08:00
2018-12-05 19:42:42 +01:00
2015-09-08 15:35:28 -07:00