Linux on ARM based TI OMAP SoCs
 help / color / mirror / Atom feed
From: phucduc.bui@gmail.com
To: peter.ujfalusi@gmail.com, broonie@kernel.org
Cc: lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com,
	jarkko.nikula@bitmer.com, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
	bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
Date: Fri,  8 May 2026 17:38:37 +0700	[thread overview]
Message-ID: <20260508103837.138142-8-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260508103837.138142-1-phucduc.bui@gmail.com>

From: bui duc phuc <phucduc.bui@gmail.com>

Convert spinlock protected sections to guard()/scoped_guard()
helpers and simplify the cleanup paths, including the
reg_cache lifetime handling in omap_mcbsp_request().

No functional change intended.

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 sound/soc/ti/omap-mcbsp.c | 54 +++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 30 deletions(-)

diff --git a/sound/soc/ti/omap-mcbsp.c b/sound/soc/ti/omap-mcbsp.c
index 411970399271..d82fef629867 100644
--- a/sound/soc/ti/omap-mcbsp.c
+++ b/sound/soc/ti/omap-mcbsp.c
@@ -290,23 +290,22 @@ static u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp)
 
 static int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
 {
-	void *reg_cache;
+	void *reg_cache __free(kfree) = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
 	int err;
 
-	reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
 	if (!reg_cache)
 		return -ENOMEM;
 
-	spin_lock(&mcbsp->lock);
-	if (!mcbsp->free) {
-		dev_err(mcbsp->dev, "McBSP%d is currently in use\n", mcbsp->id);
-		err = -EBUSY;
-		goto err_kfree;
-	}
+	scoped_guard(spinlock, &mcbsp->lock) {
+		if (!mcbsp->free) {
+			dev_err(mcbsp->dev, "McBSP%d is currently in use\n", mcbsp->id);
+			return -EBUSY;
+		}
 
-	mcbsp->free = false;
-	mcbsp->reg_cache = reg_cache;
-	spin_unlock(&mcbsp->lock);
+		mcbsp->free = false;
+		mcbsp->reg_cache = reg_cache;
+		reg_cache = NULL;
+	}
 
 	if(mcbsp->pdata->ops && mcbsp->pdata->ops->request)
 		mcbsp->pdata->ops->request(mcbsp->id - 1);
@@ -352,12 +351,11 @@ static int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
 	if (mcbsp->pdata->has_wakeup)
 		MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
 
-	spin_lock(&mcbsp->lock);
-	mcbsp->free = true;
-	mcbsp->reg_cache = NULL;
-err_kfree:
-	spin_unlock(&mcbsp->lock);
-	kfree(reg_cache);
+	scoped_guard(spinlock, &mcbsp->lock) {
+		reg_cache = mcbsp->reg_cache;
+		mcbsp->free = true;
+		mcbsp->reg_cache = NULL;
+	}
 
 	return err;
 }
@@ -395,13 +393,13 @@ static void omap_mcbsp_free(struct omap_mcbsp *mcbsp)
 	if (!mcbsp_omap1())
 		omap2_mcbsp_set_clks_src(mcbsp, MCBSP_CLKS_PRCM_SRC);
 
-	spin_lock(&mcbsp->lock);
-	if (mcbsp->free)
-		dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
-	else
-		mcbsp->free = true;
-	mcbsp->reg_cache = NULL;
-	spin_unlock(&mcbsp->lock);
+	scoped_guard(spinlock, &mcbsp->lock) {
+		if (mcbsp->free)
+			dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
+		else
+			mcbsp->free = true;
+		mcbsp->reg_cache = NULL;
+	}
 
 	kfree(reg_cache);
 }
@@ -581,16 +579,12 @@ static ssize_t dma_op_mode_store(struct device *dev,
 	if (i < 0)
 		return i;
 
-	spin_lock_irq(&mcbsp->lock);
+	guard(spinlock_irq)(&mcbsp->lock);
 	if (!mcbsp->free) {
-		size = -EBUSY;
-		goto unlock;
+		return -EBUSY;
 	}
 	mcbsp->dma_op_mode = i;
 
-unlock:
-	spin_unlock_irq(&mcbsp->lock);
-
 	return size;
 }
 
-- 
2.43.0


  parent reply	other threads:[~2026-05-08 10:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
2026-05-08 10:38 ` [PATCH 1/7] ASoC: ti: j721e-evm: Use guard() for mutex locks phucduc.bui
2026-05-08 10:38 ` [PATCH 2/7] ASoC: ti: omap-dmic: " phucduc.bui
2026-05-08 10:38 ` [PATCH 3/7] ASoC: ti: omap-hdmi: " phucduc.bui
2026-05-08 10:38 ` [PATCH 4/7] ASoC: ti: omap-mcpdm: " phucduc.bui
2026-05-08 10:38 ` [PATCH 5/7] ASoC: ti: ams-delta: Use guard() for spin locks phucduc.bui
2026-05-08 10:38 ` [PATCH 6/7] ASoC: ti: omap-mcbsp-st: " phucduc.bui
2026-05-09 12:26   ` Jarkko Nikula
2026-05-08 10:38 ` phucduc.bui [this message]
2026-05-10  1:35   ` [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling Mark Brown
2026-05-11  4:44     ` Bui Duc Phuc
2026-05-09 12:28 ` [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers Jarkko Nikula

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=20260508103837.138142-8-phucduc.bui@gmail.com \
    --to=phucduc.bui@gmail.com \
    --cc=broonie@kernel.org \
    --cc=jarkko.nikula@bitmer.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@gmail.com \
    --cc=tiwai@suse.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