Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Harendra Gautam" <harendra.gautam@oss.qualcomm.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v7 07/10] ASoC: qcom: Add QAIF PCM operations
Date: Wed, 23 Sep 2026 07:03:46 +0000	[thread overview]
Message-ID: <20260923070347.62DBD1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260923-b4-qaif-shikra-audio-v7-7-d5b6f056568e@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mm: double-free of ALSA DMA buffer on open() error path
- [Low] style: misleading DMA control macro used for config register
--

commit 7d59a73e593308e23460f4d9f07a89ab17b26f25
Author: Harendra Gautam <harendra.gautam@oss.qualcomm.com>

ASoC: qcom: Add QAIF PCM operations

Add the PCM platform callbacks needed to use QAIF DAIs for playback
and capture. Allocates DMA buffers in open(), configures in hw_params()
and prepares, and reports current DMA position.

> diff --git a/sound/soc/qcom/qaif-platform.c b/sound/soc/qcom/qaif-platform.c
> new file mode 100644
> index 0000000000000..84ce3ad9a1f2d
> --- /dev/null
> +++ b/sound/soc/qcom/qaif-platform.c

[ ... ]

> @@ -279,25 +279,25 @@ static int qaif_platform_pcmops_open(struct snd_soc_component *component,
> +	/*
> +	 * The DMA buffer/period length registers are programmed in 64-bit
> +	 * (8-byte) words, so constrain buffer and period sizes to that step
> +	 * to keep the ALSA and hardware sizes identical.
> +	 */
> +	ret = snd_pcm_hw_constraint_step(runtime, 0,
> +					 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
> +					 BIT(QAIF_DMA_BYTES_TO_WORDS_SHIFT));
> +	if (ret >= 0)
> +		ret = snd_pcm_hw_constraint_step(runtime, 0,
> +						 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
> +						 BIT(QAIF_DMA_BYTES_TO_WORDS_SHIFT));
> +	if (ret >= 0)
> +		ret = snd_pcm_hw_constraint_integer(runtime,
> +						    SNDRV_PCM_HW_PARAM_PERIODS);
> +	if (ret < 0) {
> +		dev_err(soc_runtime->dev, "setting constraints failed: %d\n", ret);
> +		if (qaif_is_cif_port(dai_id)) {
> +			WRITE_ONCE(drvdata->cif_substream[stream_dma_idx], NULL);
> +			drvdata->cif_dma_heap[stream_dma_idx] = NULL;
> +		} else {
> +			WRITE_ONCE(drvdata->aif_substream[stream_dma_idx], NULL);
> +			drvdata->aif_dma_heap[stream_dma_idx] = NULL;
> +		}
> +		mutex_lock(&drvdata->stream_lock);
> +		v->free_stream_dma_idx(drvdata, stream_dma_idx, dai_id);
> +		mutex_unlock(&drvdata->stream_lock);
> +		goto err_free_dma;
> +	}
> +	return 0;
> +
> +err_free_dma:
> +	dma_free_coherent(component->dev, dma_mem_info->alloc_size,
> +			  dma_mem_info->vaddr, dma_mem_info->dma_addr);

[Severity: High]
Does this error path leave a dangling pointer in substream->dma_buffer.area?

In qaif_platform_pcmops_open(), if setting the hardware constraints fails
(for example, if snd_pcm_hw_constraint_step() encounters an error), the code
jumps to the err_free_dma label to free the DMA memory.

However, earlier in the function, the substream's DMA buffer fields were
already populated and its type was set to SNDRV_DMA_TYPE_DEV. Because this
error path does not reset substream->dma_buffer.area to NULL, ALSA core's
teardown path (snd_pcm_lib_preallocate_free_for_all()) will find the area
pointer non-NULL and attempt to free it again using snd_dma_free_pages(),
leading to a double-free.

Could we reset the substream->dma_buffer area, bytes, and addr fields to
zero or NULL before returning the error?

> +err_free_mem_info:
> +	kfree(dma_mem_info);
> +err_free_data:
> +	kfree(data);
> +	return ret;
> +}

[ ... ]

> @@ -377,9 +377,9 @@ static int qaif_platform_pcmops_hw_params(struct snd_soc_component *component,
> +	ret = regmap_update_bits(drvdata->audio_qaif_map,
> +				 qaif_dmacfg_reg(v, idx, substream->stream, dai_id),
> +				 QAIF_DMACFG_BURST4_BIT | QAIF_DMACFG_SHRAM_WM_MASK,
> +				 QAIF_DMACFG_BURST4_BIT | QAIF_DMACTL_WM_5);

[Severity: Low]
Is the use of QAIF_DMACTL_WM_5 intentional here?

We're writing to the Configuration (CFG) register and applying the
QAIF_DMACFG_SHRAM_WM_MASK mask, but the value macro QAIF_DMACTL_WM_5 has a
Control (CTL) prefix. While this may evaluate to the correct value for the
watermark, the mismatched prefix could be misleading.

> +	if (ret)
> +		dev_err(soc_runtime->dev, "error updating DMA CFG: %d\n", ret);
> +	return ret;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923-b4-qaif-shikra-audio-v7-0-d5b6f056568e@oss.qualcomm.com?part=7

  reply	other threads:[~2026-09-23  7:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  6:48 [PATCH v7 00/10] ASoC: qcom: Add QAIF driver for Shikra audio platform Harendra Gautam
2026-09-23  6:48 ` [PATCH v7 01/10] ASoC: dt-bindings: qcom,shikra-qaif-cpu: Add binding Harendra Gautam
2026-09-23  6:59   ` sashiko-bot
2026-09-23  6:48 ` [PATCH v7 02/10] ASoC: qcom: Add QAIF shared data structures and variant interface Harendra Gautam
2026-09-23  6:59   ` sashiko-bot
2026-09-23  9:29   ` Mark Brown
2026-09-28  9:11     ` Harendra Gautam
2026-09-23  6:48 ` [PATCH v7 03/10] ASoC: qcom: Add QAIF hardware register map Harendra Gautam
2026-09-23  7:00   ` sashiko-bot
2026-09-23  6:48 ` [PATCH v7 04/10] ASoC: qcom: Add QAIF CPU DAI ops, regmap, DT parsing and platform init Harendra Gautam
2026-09-23  7:02   ` sashiko-bot
2026-09-23  9:41   ` Mark Brown
2026-09-28  9:38     ` Harendra Gautam
2026-09-28 12:17       ` Harendra Gautam
2026-09-23  6:48 ` [PATCH v7 05/10] ASoC: soc-core: Add snd_soc_of_xlate_dai_name() generic helper Harendra Gautam
2026-09-23  7:00   ` sashiko-bot
2026-09-23  6:48 ` [PATCH v7 06/10] ASoC: qcom: Switch lpass-cpu and qaif-cpu to snd_soc_of_xlate_dai_name() Harendra Gautam
2026-09-24 10:32   ` Ajay Kumar Nandam
2026-09-23  6:48 ` [PATCH v7 07/10] ASoC: qcom: Add QAIF PCM operations Harendra Gautam
2026-09-23  7:03   ` sashiko-bot [this message]
2026-09-23  9:45   ` Mark Brown
2026-09-28  9:06     ` Harendra Gautam
2026-09-23  6:48 ` [PATCH v7 08/10] ASoC: qcom: Add QAIF IRQ handling and platform register Harendra Gautam
2026-09-23  7:04   ` sashiko-bot
2026-09-23  6:48 ` [PATCH v7 09/10] ASoC: qcom: Add Shikra QAIF support Harendra Gautam
2026-09-23  7:09   ` sashiko-bot
2026-09-23  6:48 ` [PATCH v7 10/10] MAINTAINERS: Add Qualcomm QAIF driver entry Harendra Gautam
2026-09-23  9:27 ` [PATCH v7 00/10] ASoC: qcom: Add QAIF driver for Shikra audio platform Mark Brown
2026-09-28  5:44   ` Harendra Gautam

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=20260923070347.62DBD1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=harendra.gautam@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox