From: Johan Hovold <johan@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
Johan Hovold <johan@kernel.org>,
stable@vger.kernel.org, Saravana Kannan <saravanak@kernel.org>
Subject: [PATCH] spi: fix resource leaks on device setup failure
Date: Tue, 24 Mar 2026 11:30:42 +0100 [thread overview]
Message-ID: <20260324103042.980740-1-johan@kernel.org> (raw)
Make sure to call controller cleanup() on late device setup failures to
avoid leaking resources allocated by setup().
Fixes: c7299fea6769 ("spi: Fix spi device unregister flow")
Cc: stable@vger.kernel.org # 5.13
Cc: Saravana Kannan <saravanak@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/spi/spi.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 9fe9f99183bf..cb00619864cf 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -4091,7 +4091,7 @@ int spi_setup(struct spi_device *spi)
status = spi_set_cs_timing(spi);
if (status) {
mutex_unlock(&spi->controller->io_mutex);
- return status;
+ goto err_cleanup;
}
if (spi->controller->auto_runtime_pm && spi->controller->set_cs) {
@@ -4100,7 +4100,7 @@ int spi_setup(struct spi_device *spi)
mutex_unlock(&spi->controller->io_mutex);
dev_err(&spi->controller->dev, "Failed to power device: %d\n",
status);
- return status;
+ goto err_cleanup;
}
/*
@@ -4136,6 +4136,12 @@ int spi_setup(struct spi_device *spi)
status);
return status;
+
+err_cleanup:
+ if (spi->controller->cleanup)
+ spi->controller->cleanup(spi);
+
+ return status;
}
EXPORT_SYMBOL_GPL(spi_setup);
--
2.52.0
next reply other threads:[~2026-03-24 10:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 10:30 Johan Hovold [this message]
2026-03-24 13:23 ` [PATCH] spi: fix resource leaks on device setup failure Mark Brown
2026-03-24 14:13 ` Johan Hovold
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=20260324103042.980740-1-johan@kernel.org \
--to=johan@kernel.org \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=saravanak@kernel.org \
--cc=stable@vger.kernel.org \
/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