[PATCH 2/2] spi: sn-f-ospi: Use devm_mutex_init() to simplify code

Felix Gu posted 2 patches 2 weeks, 5 days ago
[PATCH 2/2] spi: sn-f-ospi: Use devm_mutex_init() to simplify code
Posted by Felix Gu 2 weeks, 5 days ago
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