mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	bcm-kernel-feedback-list@broadcom.com
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Ray Jui <rjui@broadcom.com>,
	Scott Branden <sbranden@broadcom.com>,
	linux-sound@vger.kernel.org, Kees Cook <kees+treewide@kernel.org>,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH v2 2/2] ASoC: bcm2835-i2s: Check clock enable return value
Date: Fri,  4 Dec 2026 10:17:16 +0700	[thread overview]
Message-ID: <20261204031716.9685-3-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20261204031716.9685-1-phucduc.bui@gmail.com>

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

bcm2835_i2s_start_clock() ignores the return value of
clk_prepare_enable() and marks the clock as prepared even on failure,
so bcm2835_i2s_stop_clock() later disables a clock that was never
enabled.

Return the error and only set clk_prepared on success. Propagate it
from .hw_params and .prepare, and skip clearing the FIFOs when the
clock cannot be enabled.

Fixes: 517e7a1537ae ("ASoC: bcm2835: move to use the clock framework")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---

Changes in v2: 
 - Change bcm2835_i2s_clear_fifos() to return int and propagate 
   the error to its callers.

 sound/soc/bcm/bcm2835-i2s.c | 42 ++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 12 deletions(-)

diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 68be1ded6f93..385e2ba803b8 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -125,22 +125,29 @@ struct bcm2835_i2s_dev {
 	int					clk_rate;
 };
 
-static void bcm2835_i2s_start_clock(struct bcm2835_i2s_dev *dev)
+static int bcm2835_i2s_start_clock(struct bcm2835_i2s_dev *dev)
 {
 	unsigned int provider = dev->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
+	int ret;
 
 	if (dev->clk_prepared)
-		return;
+		return 0;
 
 	switch (provider) {
 	case SND_SOC_DAIFMT_BP_FP:
 	case SND_SOC_DAIFMT_BP_FC:
-		clk_prepare_enable(dev->clk);
+		ret = clk_prepare_enable(dev->clk);
+		if (ret) {
+			dev_err(dev->dev, "Failed to enable clock: %d\n", ret);
+			return ret;
+		}
 		dev->clk_prepared = true;
 		break;
 	default:
 		break;
 	}
+
+	return 0;
 }
 
 static void bcm2835_i2s_stop_clock(struct bcm2835_i2s_dev *dev)
@@ -150,10 +157,11 @@ static void bcm2835_i2s_stop_clock(struct bcm2835_i2s_dev *dev)
 	dev->clk_prepared = false;
 }
 
-static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
-				    bool tx, bool rx)
+static int bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
+				   bool tx, bool rx)
 {
 	int timeout = 1000;
+	int ret;
 	uint32_t syncval;
 	uint32_t csreg;
 	uint32_t i2s_active_state;
@@ -173,8 +181,11 @@ static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
 
 	/* Start clock if not running */
 	clk_was_prepared = dev->clk_prepared;
-	if (!clk_was_prepared)
-		bcm2835_i2s_start_clock(dev);
+	if (!clk_was_prepared) {
+		ret = bcm2835_i2s_start_clock(dev);
+		if (ret)
+			return ret;
+	}
 
 	/* Stop I2S module */
 	regmap_update_bits(dev->i2s_regmap, BCM2835_I2S_CS_A_REG, off, 0);
@@ -214,6 +225,8 @@ static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
 	/* Restore I2S state */
 	regmap_update_bits(dev->i2s_regmap, BCM2835_I2S_CS_A_REG,
 			BCM2835_I2S_RXON | BCM2835_I2S_TXON, i2s_active_state);
+
+	return 0;
 }
 
 static int bcm2835_i2s_set_dai_fmt(struct snd_soc_dai *dai,
@@ -424,7 +437,9 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
 			dev->clk_rate = bclk_rate;
 		}
 
-		bcm2835_i2s_start_clock(dev);
+		ret = bcm2835_i2s_start_clock(dev);
+		if (ret)
+			return ret;
 	}
 
 	/* Setup the frame format */
@@ -589,7 +604,9 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
 			| BCM2835_I2S_RX(0x20), 0xffffffff);
 
 	/* Clear FIFOs */
-	bcm2835_i2s_clear_fifos(dev, true, true);
+	ret = bcm2835_i2s_clear_fifos(dev, true, true);
+	if (ret)
+		return ret;
 
 	dev_dbg(dev->dev,
 		"slots: %d width: %d rx mask: 0x%02x tx_mask: 0x%02x\n",
@@ -619,6 +636,7 @@ static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream,
 {
 	struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
 	uint32_t cs_reg;
+	int ret = 0;
 
 	/*
 	 * Clear both FIFOs if the one that should be started
@@ -630,12 +648,12 @@ static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream,
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
 			&& !(cs_reg & BCM2835_I2S_TXE))
-		bcm2835_i2s_clear_fifos(dev, true, false);
+		ret = bcm2835_i2s_clear_fifos(dev, true, false);
 	else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
 			&& (cs_reg & BCM2835_I2S_RXD))
-		bcm2835_i2s_clear_fifos(dev, false, true);
+		ret = bcm2835_i2s_clear_fifos(dev, false, true);
 
-	return 0;
+	return ret;
 }
 
 static void bcm2835_i2s_stop(struct bcm2835_i2s_dev *dev,
-- 
2.43.0


      parent reply	other threads:[~2026-12-04  3:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  3:17 [PATCH v2 0/2] ASoC: bcm2835-i2s: Fix clock handling phucduc.bui
2026-12-04  3:17 ` [PATCH v2 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path phucduc.bui
2026-12-04  3:17 ` phucduc.bui [this message]

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=20261204031716.9685-3-phucduc.bui@gmail.com \
    --to=phucduc.bui@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=broonie@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=kees+treewide@kernel.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.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

all inboxes | Powered by JetHome®