linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saravana Kannan <saravanak@google.com>
To: Mark Brown <broonie@kernel.org>, Saravana Kannan <saravanak@google.com>
Cc: Lukas Wunner <lukas@wunner.de>,
	kernel-team@android.com, linux-spi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1] spi: Don't have controller clean up spi device before driver unbind
Date: Tue,  4 May 2021 20:14:16 -0700	[thread overview]
Message-ID: <20210505031416.30128-1-saravanak@google.com> (raw)

When a spi device is unregistered and triggers a driver unbind, the
driver might need to access the spi device. So, don't have the
controller clean up the spi device before the driver is unbound. Clean
up the spi device after the driver is unbound.

Fixes: c7299fea6769 ("spi: Fix spi device unregister flow")
Reported-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Saravana Kannan <saravanak@google.com>
---
Lukas,

Can you test this out please?

Thanks,
Saravana

 drivers/spi/spi.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 2350d131871b..b856f4a1e3a4 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -401,6 +401,12 @@ static int spi_probe(struct device *dev)
 	return ret;
 }
 
+static void spi_cleanup(struct spi_device *spi)
+{
+	if (spi->controller->cleanup)
+		spi->controller->cleanup(spi);
+}
+
 static int spi_remove(struct device *dev)
 {
 	const struct spi_driver		*sdrv = to_spi_driver(dev->driver);
@@ -415,6 +421,7 @@ static int spi_remove(struct device *dev)
 				 ERR_PTR(ret));
 	}
 
+	spi_cleanup(to_spi_device(dev));
 	dev_pm_domain_detach(dev, true);
 
 	return 0;
@@ -554,12 +561,6 @@ static int spi_dev_check(struct device *dev, void *data)
 	return 0;
 }
 
-static void spi_cleanup(struct spi_device *spi)
-{
-	if (spi->controller->cleanup)
-		spi->controller->cleanup(spi);
-}
-
 /**
  * spi_add_device - Add spi_device allocated with spi_alloc_device
  * @spi: spi_device to register
@@ -714,8 +715,6 @@ void spi_unregister_device(struct spi_device *spi)
 	if (!spi)
 		return;
 
-	spi_cleanup(spi);
-
 	if (spi->dev.of_node) {
 		of_node_clear_flag(spi->dev.of_node, OF_POPULATED);
 		of_node_put(spi->dev.of_node);
-- 
2.31.1.527.g47e6f16901-goog


             reply	other threads:[~2021-05-05  3:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05  3:14 Saravana Kannan [this message]
2021-05-05  5:48 ` [PATCH v1] spi: Don't have controller clean up spi device before driver unbind Lukas Wunner
2021-05-05 12:38   ` Mark Brown
2021-05-05 16:31   ` Saravana Kannan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210505031416.30128-1-saravanak@google.com \
    --to=saravanak@google.com \
    --cc=broonie@kernel.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lukas@wunner.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).