[PATCH] ALSA: atmel: ac97c: use platform helpers and devm cleanup

Rosen Penev posted 1 patch 3 days ago
sound/atmel/ac97c.c | 67 ++++++++++++---------------------------------
1 file changed, 17 insertions(+), 50 deletions(-)
[PATCH] ALSA: atmel: ac97c: use platform helpers and devm cleanup
Posted by Rosen Penev 3 days ago
Convert atmel_ac97c_probe() to the managed APIs. Replace the open-coded
platform_get_resource() + ioremap() with devm_platform_ioremap_resource(),
which requests and maps the AC97C register window in one call. Switch the
clock to devm_clk_get_enabled(), the card to snd_devm_card_new(), and the
interrupt to devm_request_irq(). The now-unnecessary error-path cleanup
and the manual teardown in atmel_ac97c_remove() are dropped, since devm
handles them.

platform_get_irq() was already used; tighten its error check to irq < 0.

Both resource and IRQ lookups are equivalent for a platform-backed
device. The AC97C register window is owned solely by this driver, so the
new region request cannot conflict with another claimant, and it is
mapped exactly once (no double mapping).

No functional change; built for ARM (allmodconfig + SND_ATMEL_AC97C)
with LLVM=1 and sound/atmel/ac97c.o compiles cleanly.

Assisted-by: opencode:hy3-free
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 sound/atmel/ac97c.c | 67 ++++++++++++---------------------------------
 1 file changed, 17 insertions(+), 50 deletions(-)

diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index e394205f469b..234549e17351 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -693,7 +693,7 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
 	struct device			*dev = &pdev->dev;
 	struct snd_card			*card;
 	struct atmel_ac97c		*chip;
-	struct resource			*regs;
+	void __iomem			*regs;
 	struct clk			*pclk;
 	static const struct snd_ac97_bus_ops	ops = {
 		.write	= atmel_ac97c_write,
@@ -702,42 +702,34 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
 	int				retval;
 	int				irq;
 
-	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!regs) {
-		dev_dbg(&pdev->dev, "no memory resource\n");
-		return -ENXIO;
-	}
+	regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(regs))
+		return PTR_ERR(regs);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		dev_dbg(&pdev->dev, "could not get irq: %d\n", irq);
+	if (irq < 0)
 		return irq;
-	}
 
-	pclk = clk_get(&pdev->dev, "ac97_clk");
+	pclk = devm_clk_get_enabled(&pdev->dev, "ac97_clk");
 	if (IS_ERR(pclk)) {
 		dev_dbg(&pdev->dev, "no peripheral clock\n");
 		return PTR_ERR(pclk);
 	}
-	retval = clk_prepare_enable(pclk);
-	if (retval)
-		goto err_prepare_enable;
 
-	retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
+	retval = snd_devm_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
 			      SNDRV_DEFAULT_STR1, THIS_MODULE,
 			      sizeof(struct atmel_ac97c), &card);
 	if (retval) {
 		dev_dbg(&pdev->dev, "could not create sound card device\n");
-		goto err_snd_card_new;
+		return retval;
 	}
 
 	chip = get_chip(card);
 
-	retval = request_irq(irq, atmel_ac97c_interrupt, 0, "AC97C", chip);
-	if (retval) {
-		dev_dbg(&pdev->dev, "unable to request irq %d\n", irq);
-		goto err_request_irq;
-	}
+	retval = devm_request_irq(&pdev->dev, irq, atmel_ac97c_interrupt, 0, "AC97C", chip);
+	if (retval)
+		return retval;
+
 	chip->irq = irq;
 
 	spin_lock_init(&chip->lock);
@@ -749,13 +741,7 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
 	chip->card = card;
 	chip->pclk = pclk;
 	chip->pdev = pdev;
-	chip->regs = ioremap(regs->start, resource_size(regs));
-
-	if (!chip->regs) {
-		dev_dbg(&pdev->dev, "could not remap register memory\n");
-		retval = -ENOMEM;
-		goto err_ioremap;
-	}
+	chip->regs = regs;
 
 	chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH);
 	if (IS_ERR(chip->reset_pin))
@@ -770,25 +756,25 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
 	retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
 	if (retval) {
 		dev_dbg(&pdev->dev, "could not register on ac97 bus\n");
-		goto err_ac97_bus;
+		return retval;
 	}
 
 	retval = atmel_ac97c_mixer_new(chip);
 	if (retval) {
 		dev_dbg(&pdev->dev, "could not register ac97 mixer\n");
-		goto err_ac97_bus;
+		return retval;
 	}
 
 	retval = atmel_ac97c_pcm_new(chip);
 	if (retval) {
 		dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
-		goto err_ac97_bus;
+		return retval;
 	}
 
 	retval = snd_card_register(card);
 	if (retval) {
 		dev_dbg(&pdev->dev, "could not register sound card\n");
-		goto err_ac97_bus;
+		return retval;
 	}
 
 	platform_set_drvdata(pdev, card);
@@ -797,18 +783,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
 			chip->regs, irq);
 
 	return 0;
-
-err_ac97_bus:
-	iounmap(chip->regs);
-err_ioremap:
-	free_irq(irq, chip);
-err_request_irq:
-	snd_card_free(card);
-err_snd_card_new:
-	clk_disable_unprepare(pclk);
-err_prepare_enable:
-	clk_put(pclk);
-	return retval;
 }
 
 static int atmel_ac97c_suspend(struct device *pdev)
@@ -839,13 +813,6 @@ static void atmel_ac97c_remove(struct platform_device *pdev)
 	ac97c_writel(chip, CAMR, 0);
 	ac97c_writel(chip, COMR, 0);
 	ac97c_writel(chip, MR,   0);
-
-	clk_disable_unprepare(chip->pclk);
-	clk_put(chip->pclk);
-	iounmap(chip->regs);
-	free_irq(chip->irq, chip);
-
-	snd_card_free(card);
 }
 
 static struct platform_driver atmel_ac97c_driver = {
-- 
2.55.0
Re: [PATCH] ALSA: atmel: ac97c: use platform helpers and devm cleanup
Posted by Takashi Iwai 2 days, 12 hours ago
On Wed, 22 Jul 2026 00:54:11 +0200,
Rosen Penev wrote:
> 
> Convert atmel_ac97c_probe() to the managed APIs. Replace the open-coded
> platform_get_resource() + ioremap() with devm_platform_ioremap_resource(),
> which requests and maps the AC97C register window in one call. Switch the
> clock to devm_clk_get_enabled(), the card to snd_devm_card_new(), and the
> interrupt to devm_request_irq(). The now-unnecessary error-path cleanup
> and the manual teardown in atmel_ac97c_remove() are dropped, since devm
> handles them.
> 
> platform_get_irq() was already used; tighten its error check to irq < 0.
> 
> Both resource and IRQ lookups are equivalent for a platform-backed
> device. The AC97C register window is owned solely by this driver, so the
> new region request cannot conflict with another claimant, and it is
> mapped exactly once (no double mapping).
> 
> No functional change; built for ARM (allmodconfig + SND_ATMEL_AC97C)
> with LLVM=1 and sound/atmel/ac97c.o compiles cleanly.
> 
> Assisted-by: opencode:hy3-free
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Applied to for-next branch.  Thanks.


Takashi