public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Venkata Prasad Potturu <venkataprasad.potturu@amd.com>
Cc: <broonie@kernel.org>, <alsa-devel@alsa-project.org>,
	<vsujithkumar.reddy@amd.com>, <Vijendar.Mukunda@amd.com>,
	<Basavaraj.Hiregoudar@amd.com>, <Sunil-kumar.Dommati@amd.com>,
	<ssabakar@amd.com>, Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	V sujith kumar Reddy <Vsujithkumar.Reddy@amd.com>,
	"Charles Keepax" <ckeepax@opensource.cirrus.com>,
	Yang Yingliang <yangyingliang@huawei.com>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] ASoC: amd: acp: Initialize list to store acp_stream during pcm_open
Date: Fri, 22 Jul 2022 15:41:02 +0200	[thread overview]
Message-ID: <87h739464x.wl-tiwai@suse.de> (raw)
In-Reply-To: <20220722133530.3314087-1-venkataprasad.potturu@amd.com>

On Fri, 22 Jul 2022 15:35:22 +0200,
Venkata Prasad Potturu wrote:
> 
> From: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
> 
> We are currently allocating acp_stream during pcm_open and saving
> it in static array corresponds to array index calculated based on
> cpu dai->driver id. This approach will fail if we have single dai
> linked to multiple pcm device as we will have same dai->driver id
> or array index for multiple pcm open. Initialize new linked list
> stream_list to store opened pcm stream info dynamically.

If an IRQ handler refers to the linked list, make sure that no list
change will happen concurrently during the IRQ handling.  It seems
that you have no protection for it yet.


thanks,

Takashi

> 
> Signed-off-by: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
> Signed-off-by: Venkata Prasad Potturu <venkataprasad.potturu@amd.com>
> Reviewed-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
> ---
> 
> Changes since v1:
>     -- Fix compile error and remove unused variable.
> 
>  sound/soc/amd/acp/acp-platform.c | 33 ++++++++++++--------------------
>  sound/soc/amd/acp/amd.h          |  3 ++-
>  2 files changed, 14 insertions(+), 22 deletions(-)
> 
> diff --git a/sound/soc/amd/acp/acp-platform.c b/sound/soc/amd/acp/acp-platform.c
> index 10730d33c3b0..20c0f75f7c97 100644
> --- a/sound/soc/amd/acp/acp-platform.c
> +++ b/sound/soc/amd/acp/acp-platform.c
> @@ -94,7 +94,7 @@ static irqreturn_t i2s_irq_handler(int irq, void *data)
>  	struct acp_resource *rsrc = adata->rsrc;
>  	struct acp_stream *stream;
>  	u16 i2s_flag = 0;
> -	u32 ext_intr_stat, ext_intr_stat1, i;
> +	u32 ext_intr_stat, ext_intr_stat1;
>  
>  	if (!adata)
>  		return IRQ_NONE;
> @@ -104,8 +104,7 @@ static irqreturn_t i2s_irq_handler(int irq, void *data)
>  
>  	ext_intr_stat = readl(ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used));
>  
> -	for (i = 0; i < ACP_MAX_STREAM; i++) {
> -		stream = adata->stream[i];
> +	list_for_each_entry(stream, &adata->stream_list, list) {
>  		if (stream && (ext_intr_stat & stream->irq_bit)) {
>  			writel(stream->irq_bit,
>  			       ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used));
> @@ -146,9 +145,8 @@ static void config_pte_for_stream(struct acp_dev_data *adata, struct acp_stream
>  	writel(0x01, adata->acp_base + ACPAXI2AXI_ATU_CTRL);
>  }
>  
> -static void config_acp_dma(struct acp_dev_data *adata, int cpu_id, int size)
> +static void config_acp_dma(struct acp_dev_data *adata, struct acp_stream *stream, int size)
>  {
> -	struct acp_stream *stream = adata->stream[cpu_id];
>  	struct snd_pcm_substream *substream = stream->substream;
>  	struct acp_resource *rsrc = adata->rsrc;
>  	dma_addr_t addr = substream->dma_buffer.addr;
> @@ -174,13 +172,10 @@ static void config_acp_dma(struct acp_dev_data *adata, int cpu_id, int size)
>  
>  static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_substream *substream)
>  {
> -	struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
> -	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
>  	struct snd_pcm_runtime *runtime = substream->runtime;
>  	struct device *dev = component->dev;
>  	struct acp_dev_data *adata = dev_get_drvdata(dev);
>  	struct acp_stream *stream;
> -	int stream_id = cpu_dai->driver->id * 2 + substream->stream;
>  	int ret;
>  
>  	stream = kzalloc(sizeof(*stream), GFP_KERNEL);
> @@ -188,7 +183,8 @@ static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_subs
>  		return -ENOMEM;
>  
>  	stream->substream = substream;
> -	adata->stream[stream_id] = stream;
> +
> +	list_add_tail(&stream->list, &adata->stream_list);
>  
>  	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
>  		runtime->hw = acp_pcm_hardware_playback;
> @@ -212,16 +208,13 @@ static int acp_dma_hw_params(struct snd_soc_component *component,
>  			     struct snd_pcm_substream *substream,
>  			     struct snd_pcm_hw_params *params)
>  {
> -	struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
>  	struct acp_dev_data *adata = snd_soc_component_get_drvdata(component);
> -	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
>  	struct acp_stream *stream = substream->runtime->private_data;
> -	int stream_id = cpu_dai->driver->id * 2 + substream->stream;
>  	u64 size = params_buffer_bytes(params);
>  
>  	/* Configure ACP DMA block with params */
>  	config_pte_for_stream(adata, stream);
> -	config_acp_dma(adata, stream_id, size);
> +	config_acp_dma(adata, stream, size);
>  
>  	return 0;
>  }
> @@ -261,16 +254,11 @@ static int acp_dma_new(struct snd_soc_component *component,
>  static int acp_dma_close(struct snd_soc_component *component,
>  			 struct snd_pcm_substream *substream)
>  {
> -	struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
> -	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
> -	struct device *dev = component->dev;
> -	struct acp_dev_data *adata = dev_get_drvdata(dev);
> -	struct acp_stream *stream;
> -	int stream_id = cpu_dai->driver->id * 2 + substream->stream;
> +	struct acp_stream *stream = substream->runtime->private_data;
>  
> -	stream = adata->stream[stream_id];
> +	/* Remove entry from list */
> +	list_del(&stream->list);
>  	kfree(stream);
> -	adata->stream[stream_id] = NULL;
>  
>  	return 0;
>  }
> @@ -305,6 +293,9 @@ int acp_platform_register(struct device *dev)
>  		dev_err(dev, "Fail to register acp i2s component\n");
>  		return status;
>  	}
> +
> +	INIT_LIST_HEAD(&adata->stream_list);
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_NS_GPL(acp_platform_register, SND_SOC_ACP_COMMON);
> diff --git a/sound/soc/amd/acp/amd.h b/sound/soc/amd/acp/amd.h
> index af9603724a68..148a9ab6206d 100644
> --- a/sound/soc/amd/acp/amd.h
> +++ b/sound/soc/amd/acp/amd.h
> @@ -91,6 +91,7 @@ struct acp_chip_info {
>  };
>  
>  struct acp_stream {
> +	struct list_head list;
>  	struct snd_pcm_substream *substream;
>  	int irq_bit;
>  	int dai_id;
> @@ -123,7 +124,7 @@ struct acp_dev_data {
>  	struct snd_soc_dai_driver *dai_driver;
>  	int num_dai;
>  
> -	struct acp_stream *stream[ACP_MAX_STREAM];
> +	struct list_head stream_list;
>  
>  	struct snd_soc_acpi_mach *machines;
>  	struct platform_device *mach_dev;
> -- 
> 2.25.1
> 

  reply	other threads:[~2022-07-22 13:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 13:35 [PATCH v2] ASoC: amd: acp: Initialize list to store acp_stream during pcm_open Venkata Prasad Potturu
2022-07-22 13:41 ` Takashi Iwai [this message]
     [not found]   ` <PH7PR12MB5951A322E8613E1A782ACCF3E9969@PH7PR12MB5951.namprd12.prod.outlook.com>
2022-07-28 11:14     ` Mark Brown

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=87h739464x.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=AjitKumar.Pandey@amd.com \
    --cc=Basavaraj.Hiregoudar@amd.com \
    --cc=Sunil-kumar.Dommati@amd.com \
    --cc=Vijendar.Mukunda@amd.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=ssabakar@amd.com \
    --cc=tiwai@suse.com \
    --cc=venkataprasad.potturu@amd.com \
    --cc=vsujithkumar.reddy@amd.com \
    --cc=yangyingliang@huawei.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