spi: Fix spi device unregister flow
authorSaravana Kannan <saravanak@google.com>
Mon, 26 Apr 2021 23:56:38 +0000 (16:56 -0700)
committerMark Brown <broonie@kernel.org>
Wed, 28 Apr 2021 15:34:58 +0000 (16:34 +0100)
commitc7299fea67696db5bd09d924d1f1080d894f92ef
treebda8542b8151eee9347d7995cd0156415838e11b
parent86527bcbc88922ea40df05d28189ee15489d2cf1
spi: Fix spi device unregister flow

When an SPI device is unregistered, the spi->controller->cleanup() is
called in the device's release callback. That's wrong for a couple of
reasons:

1. spi_dev_put() can be called before spi_add_device() is called. And
   it's spi_add_device() that calls spi_setup(). This will cause clean()
   to get called without the spi device ever being setup.

2. There's no guarantee that the controller's driver would be present by
   the time the spi device's release function gets called.

3. It also causes "sleeping in atomic context" stack dump[1] when device
   link deletion code does a put_device() on the spi device.

Fix these issues by simply moving the cleanup from the device release
callback to the actual spi_unregister_device() function.

[1] - https://lore.kernel.org/lkml/CAHp75Vc=FCGcUyS0v6fnxme2YJ+qD+Y-hQDQLa2JhWNON9VmsQ@mail.gmail.com/

Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20210426235638.1285530-1-saravanak@google.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c