All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mohammad Rafi Shaik" <mohammad.rafi.shaik@oss.qualcomm.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v7 2/3] ASoC: qcom: q6apm-lpass-dais: Add MI2S clock control
Date: Fri, 24 Jul 2026 18:46:04 +0000	[thread overview]
Message-ID: <20260724184605.2B9831F01558@smtp.kernel.org> (raw)
In-Reply-To: <20260724182446.1484894-3-mohammad.rafi.shaik@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing freq == 0 check in set_sysclk causes permanent clock enable leak
- [Low] Memory leak of clock references on duplicate DAI nodes in DT
--

--- Patch [2]: [PATCH v7 2/3] ASoC: qcom: q6apm-lpass-dais: Add MI2S clock control ---
commit bf9b1226eaeb15dbad44a1a60c78519c600713d4
Author: Mohammad Rafi Shaik <mohammad.rafi.shaik@oss.qualcomm.com>

ASoC: qcom: q6apm-lpass-dais: Add MI2S clock control

This patch adds support for MI2S clock control within q6apm-lpass DAIs.
It retrieves MCLK and BCLK handles from the device tree for each MI2S port
and manages them via the DAI set_sysclk callback.

> diff --git a/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c b/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c
> index 006b283484d9e..e68e8b000e079 100644
> --- a/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c
> +++ b/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c

[ ... ]

> @@ -251,6 +292,62 @@ static int q6apm_lpass_dai_startup(struct snd_pcm_substream *substream, struct s
> +static int q6i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir)
> +{
> +	struct q6apm_lpass_dai_data *dai_data = dev_get_drvdata(dai->dev);
> +	struct clk *sysclk = NULL;
> +	bool *enabled = NULL;
> +	int ret = 0;
> +
> +	switch (clk_id) {
> +	case LPAIF_MI2S_MCLK:
> +		sysclk = dai_data->priv[dai->id].mclk;
> +		enabled = &dai_data->priv[dai->id].mclk_enabled;
> +		break;
> +	case LPAIF_MI2S_BCLK:
> +		sysclk = dai_data->priv[dai->id].bclk;
> +		enabled = &dai_data->priv[dai->id].bclk_enabled;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	if (sysclk) {
> +		ret = clk_set_rate(sysclk, freq);
> +		if (ret) {
> +			dev_err(dai->dev, "Error, Unable to set rate (%d) for sysclk %d\n",
> +				freq, clk_id);
> +			return ret;
> +		}
> +
> +		if (*enabled)
> +			return 0;
> +
> +		ret = clk_prepare_enable(sysclk);

[Severity: High]
Will this leak the clock enable count if a machine driver calls
snd_soc_dai_set_sysclk() with freq == 0 during teardown?

Many ASoC machine drivers call snd_soc_dai_set_sysclk() with a frequency
of 0 to explicitly disable clocks. If this happens after the DAI's shutdown
hook has already cleared the enabled boolean to false, this function will
see enabled == false and incorrectly call clk_prepare_enable() again.

Without a subsequent hook to turn it off, the clock would remain permanently
enabled, preventing the system from entering low-power states.

Should there be a check for freq == 0 to handle clock disable requests?

> +		if (ret) {
> +			dev_err(dai->dev, "Error, Unable to prepare (%d) sysclk\n", clk_id);
> +			return ret;
> +		}
> +
> +		*enabled = true;
> +	}
> +
> +	return ret;
> +}

[ ... ]

> @@ -297,6 +395,64 @@ static const struct snd_soc_component_driver q6apm_lpass_dai_component = {
> +static int of_q6apm_parse_dai_data(struct device *dev,
> +				   struct q6apm_lpass_dai_data *data)
> +{
> +	int ret;
> +
> +	for_each_child_of_node_scoped(dev->of_node, node) {
> +		struct q6apm_dai_priv_data *priv;
> +		int id;
> +
> +		ret = of_property_read_u32(node, "reg", &id);
> +		if (ret || id < 0 || id >= APM_PORT_MAX) {
> +			dev_err(dev, "valid dai id not found:%d\n", ret);
> +			continue;
> +		}
> +
> +		switch (id) {
> +		/* MI2S specific properties */
> +		case PRIMARY_MI2S_RX ... QUATERNARY_MI2S_TX:
> +		case QUINARY_MI2S_RX ... QUINARY_MI2S_TX:
> +		case SENARY_MI2S_RX ... SENARY_MI2S_TX:
> +			priv = &data->priv[id];
> +			priv->mclk = of_clk_get_by_name(node, "mclk");

[Severity: Low]
Does this leak the CCF clock references if a malformed device tree provides
multiple DAI child nodes with the same reg value?

If multiple nodes map to the same id index, the assignments to priv->mclk
and priv->bclk will overwrite the previously acquired clock pointers from
earlier iterations without calling clk_put(), leaking the previous clock
references.

> +			if (IS_ERR(priv->mclk)) {
> +				int err = PTR_ERR(priv->mclk);
> +
> +				priv->mclk = NULL;
> +				if (err == -EPROBE_DEFER) {
> +					q6apm_lpass_dai_put_clocks(data);
> +					return dev_err_probe(dev, err,
> +							     "unable to get mi2s mclk\n");
> +				}
> +			}
> +
> +			priv->bclk = of_clk_get_by_name(node, "bclk");

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724182446.1484894-1-mohammad.rafi.shaik@oss.qualcomm.com?part=2

  reply	other threads:[~2026-07-24 18:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 18:24 [PATCH v7 0/3] ASoC: qcom: qdsp6: Add MI2S clock control Mohammad Rafi Shaik
2026-07-24 18:24 ` [PATCH v7 1/3] ASoC: dt-bindings: qcom,q6apm-lpass-dais: Document DAI subnode Mohammad Rafi Shaik
2026-07-24 18:24 ` [PATCH v7 2/3] ASoC: qcom: q6apm-lpass-dais: Add MI2S clock control Mohammad Rafi Shaik
2026-07-24 18:46   ` sashiko-bot [this message]
2026-07-24 18:24 ` [PATCH v7 3/3] ASoC: qcom: sc8280xp: enhance machine driver for board-specific config Mohammad Rafi Shaik
2026-07-24 18:37   ` sashiko-bot

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=20260724184605.2B9831F01558@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=mohammad.rafi.shaik@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.