public inbox for linux-spi@vger.kernel.org
 help / color / mirror / Atom feed
From: Felix Gu <ustc.gu@gmail.com>
To: Mark Brown <broonie@kernel.org>,
	 Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Felix Gu <ustc.gu@gmail.com>
Subject: [PATCH 2/2] spi: sn-f-ospi: Use devm_mutex_init() to simplify code
Date: Thu, 19 Mar 2026 00:12:35 +0800	[thread overview]
Message-ID: <20260319-sn-f-v1-2-33a6738d2da8@gmail.com> (raw)
In-Reply-To: <20260319-sn-f-v1-0-33a6738d2da8@gmail.com>

Switch to devm_mutex_init() to handle mutex destruction automatically.
This simplifies the error paths in probe() and removes the need for an
explicit mutex_destroy() in remove() callback.

Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/spi/spi-sn-f-ospi.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
index 1f554aa7ca27..3c61c799723b 100644
--- a/drivers/spi/spi-sn-f-ospi.c
+++ b/drivers/spi/spi-sn-f-ospi.c
@@ -642,29 +642,15 @@ static int f_ospi_probe(struct platform_device *pdev)
 	if (IS_ERR(ospi->clk))
 		return PTR_ERR(ospi->clk);
 
-	mutex_init(&ospi->mlock);
-
-	ret = f_ospi_init(ospi);
+	ret = devm_mutex_init(dev, &ospi->mlock);
 	if (ret)
-		goto err_destroy_mutex;
+		return ret;
 
-	ret = devm_spi_register_controller(dev, ctlr);
+	ret = f_ospi_init(ospi);
 	if (ret)
-		goto err_destroy_mutex;
-
-	return 0;
-
-err_destroy_mutex:
-	mutex_destroy(&ospi->mlock);
-
-	return ret;
-}
-
-static void f_ospi_remove(struct platform_device *pdev)
-{
-	struct f_ospi *ospi = platform_get_drvdata(pdev);
+		return ret;
 
-	mutex_destroy(&ospi->mlock);
+	return devm_spi_register_controller(dev, ctlr);
 }
 
 static const struct of_device_id f_ospi_dt_ids[] = {
@@ -679,7 +665,6 @@ static struct platform_driver f_ospi_driver = {
 		.of_match_table = f_ospi_dt_ids,
 	},
 	.probe = f_ospi_probe,
-	.remove = f_ospi_remove,
 };
 module_platform_driver(f_ospi_driver);
 

-- 
2.43.0


  parent reply	other threads:[~2026-03-18 16:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 16:12 [PATCH 0/2] spi: sn-f-ospi: two small fixes Felix Gu
2026-03-18 16:12 ` [PATCH 1/2] spi: sn-f-ospi: Fix resource leak in f_ospi_probe() Felix Gu
2026-03-18 16:12 ` Felix Gu [this message]
2026-03-23 14:52 ` [PATCH 0/2] spi: sn-f-ospi: two small fixes Mark Brown

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=20260319-sn-f-v1-2-33a6738d2da8@gmail.com \
    --to=ustc.gu@gmail.com \
    --cc=broonie@kernel.org \
    --cc=hayashi.kunihiko@socionext.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@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