public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: Radu Pirea <radu_nicolae.pirea@upb.ro>,
	Ryan Wanner <ryan.wanner@microchip.com>,
	William Zhang <william.zhang@broadcom.com>,
	Kursad Oney <kursad.oney@broadcom.com>,
	Jonas Gorski <jonas.gorski@gmail.com>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Johan Hovold <johan@kernel.org>
Subject: [PATCH 02/19] spi: atmel: switch to managed controller allocation
Date: Wed, 29 Apr 2026 11:13:16 +0200	[thread overview]
Message-ID: <20260429091333.165363-3-johan@kernel.org> (raw)
In-Reply-To: <20260429091333.165363-1-johan@kernel.org>

Switch to device managed controller allocation to simplify error
handling and to avoid having to take another reference during
deregistration.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-atmel.c | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 42db85d7ff8e..25aa294631c8 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -1528,7 +1528,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
 		return PTR_ERR(clk);
 
 	/* setup spi core then atmel-specific driver state */
-	host = spi_alloc_host(&pdev->dev, sizeof(*as));
+	host = devm_spi_alloc_host(&pdev->dev, sizeof(*as));
 	if (!host)
 		return -ENOMEM;
 
@@ -1555,18 +1555,15 @@ static int atmel_spi_probe(struct platform_device *pdev)
 
 	as->pdev = pdev;
 	as->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &regs);
-	if (IS_ERR(as->regs)) {
-		ret = PTR_ERR(as->regs);
-		goto out_unmap_regs;
-	}
+	if (IS_ERR(as->regs))
+		return PTR_ERR(as->regs);
+
 	as->phybase = regs->start;
 	as->irq = irq;
 	as->clk = clk;
 	as->gclk = devm_clk_get_optional(&pdev->dev, "spi_gclk");
-	if (IS_ERR(as->gclk)) {
-		ret = PTR_ERR(as->gclk);
-		goto out_unmap_regs;
-	}
+	if (IS_ERR(as->gclk))
+		return PTR_ERR(as->gclk);
 
 	init_completion(&as->xfer_completion);
 
@@ -1576,11 +1573,10 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	as->use_pdc = false;
 	if (as->caps.has_dma_support) {
 		ret = atmel_spi_configure_dma(host, as);
-		if (ret == 0) {
+		if (ret == 0)
 			as->use_dma = true;
-		} else if (ret == -EPROBE_DEFER) {
-			goto out_unmap_regs;
-		}
+		else if (ret == -EPROBE_DEFER)
+			return ret;
 	} else if (as->caps.has_pdc_support) {
 		as->use_pdc = true;
 	}
@@ -1620,12 +1616,12 @@ static int atmel_spi_probe(struct platform_device *pdev)
 					0, dev_name(&pdev->dev), host);
 	}
 	if (ret)
-		goto out_unmap_regs;
+		return ret;
 
 	/* Initialize the hardware */
 	ret = clk_prepare_enable(clk);
 	if (ret)
-		goto out_free_irq;
+		return ret;
 
 	/*
 	 * In cases where the peripheral clock is higher,the FLEX_SPI_CSRx.SCBR
@@ -1677,9 +1673,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	clk_disable_unprepare(as->gclk);
 out_disable_clk:
 	clk_disable_unprepare(clk);
-out_free_irq:
-out_unmap_regs:
-	spi_controller_put(host);
+
 	return ret;
 }
 
@@ -1688,8 +1682,6 @@ static void atmel_spi_remove(struct platform_device *pdev)
 	struct spi_controller	*host = platform_get_drvdata(pdev);
 	struct atmel_spi	*as = spi_controller_get_devdata(host);
 
-	spi_controller_get(host);
-
 	pm_runtime_get_sync(&pdev->dev);
 
 	spi_unregister_controller(host);
@@ -1720,8 +1712,6 @@ static void atmel_spi_remove(struct platform_device *pdev)
 
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-
-	spi_controller_put(host);
 }
 
 static int atmel_spi_runtime_suspend(struct device *dev)
-- 
2.53.0


  parent reply	other threads:[~2026-04-29  9:14 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29  9:13 [PATCH 00/19] spi: switch to managed controller allocation (part 1/3) Johan Hovold
2026-04-29  9:13 ` [PATCH 01/19] spi: at91-usart: switch to managed controller allocation Johan Hovold
2026-04-29  9:13 ` Johan Hovold [this message]
2026-04-29  9:13 ` [PATCH 03/19] spi: bcm63xx: " Johan Hovold
2026-04-29  9:13 ` [PATCH 04/19] spi: bcm63xx-hsspi: " Johan Hovold
2026-04-29 18:13   ` William Zhang
2026-04-29  9:13 ` [PATCH 05/19] spi: cadence: " Johan Hovold
2026-04-29  9:13 ` [PATCH 06/19] spi: octeon: " Johan Hovold
2026-04-29  9:13 ` [PATCH 07/19] spi: cavium-thunderx: " Johan Hovold
2026-04-29  9:13 ` [PATCH 08/19] spi: coldfire-qspi: " Johan Hovold
2026-04-29  9:13 ` [PATCH 09/19] spi: dln2: " Johan Hovold
2026-04-29  9:13 ` [PATCH 10/19] spi: ep93xx: " Johan Hovold
2026-04-29  9:13 ` [PATCH 11/19] spi: fsl: " Johan Hovold
2026-04-29  9:13 ` [PATCH 12/19] spi: fsl-espi: " Johan Hovold
2026-04-29  9:13 ` [PATCH 13/19] spi: img-spfi: " Johan Hovold
2026-04-29  9:13 ` [PATCH 14/19] spi: lantiq-ssc: " Johan Hovold
2026-04-29  9:13 ` [PATCH 15/19] spi: meson-spicc: " Johan Hovold
2026-04-29  9:13 ` [PATCH 16/19] spi: mxs: " Johan Hovold
2026-04-29  9:13 ` [PATCH 17/19] spi: npcm-pspi: " Johan Hovold
2026-04-29  9:13 ` [PATCH 18/19] spi: omap2-mcspi: " Johan Hovold
2026-04-30  0:30   ` Mark Brown
2026-04-30  7:12     ` Johan Hovold
2026-04-30 10:05       ` Mark Brown
2026-04-30 10:12         ` Johan Hovold
2026-04-29  9:13 ` [PATCH 19/19] spi: orion: " Johan Hovold
2026-05-04 13:09 ` (subset) [PATCH 00/19] spi: switch to managed controller allocation (part 1/3) 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=20260429091333.165363-3-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=broonie@kernel.org \
    --cc=jonas.gorski@gmail.com \
    --cc=kursad.oney@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=radu_nicolae.pirea@upb.ro \
    --cc=ryan.wanner@microchip.com \
    --cc=william.zhang@broadcom.com \
    /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