Skip to contentSkip to conversation

ASoC: atmel-pcm-dma: Leaking memory in atmel_pcm_hw_params

DISCUSSION Lars-Peter Clausen 2 participants 4 messages Mar 17, 2013 – Mar 19, 2013

lore
Share & tools
lore
#0 lore raw

Hi,

The dmaengine based pcm driver for atmel calls snd_dmaengine_pcm_open from it's hw_params callback. There is nothing preventing an application calling hw_params more than once. snd_dmaengine_pcm_open allocates a new prtd struct each time it gets called. So in case hw_params is called multiple times we leak memory here.

Is there any specific reason why snd_dmaengine_pcm_open() needs to be called from the hw_params callback and why it can't be called from the open callback? The filter function depends on the data returned by snd_soc_dai_get_dma_data(), but as far as I can see the DAI driver calls snd_soc_dai_set_dma_data() from its startup() callback, so the data is available in the PCM drivers open callback.

- Lars

#1 lore raw

Hi Lars,

Quoted 7 lines · Lars-Peter Clausen

Hi,

The dmaengine based pcm driver for atmel calls snd_dmaengine_pcm_open from it's hw_params callback. There is nothing preventing an application calling hw_params more than once. snd_dmaengine_pcm_open allocates a new prtd struct each time it gets called. So in case hw_params is called multiple times we leak memory here.

I use alsa utils and don't meet this issue. Please point out which software you use meet this issue.

Quoted 3 lines

Is there any specific reason why snd_dmaengine_pcm_open() needs to be called from the hw_params callback and why it can't be called from the open callback?

This is because dma data setting and usage.

The filter function depends on the data returned by

Quoted 3 lines

snd_soc_dai_get_dma_data(), but as far as I can see the DAI driver calls snd_soc_dai_set_dma_data() from its startup() callback, so the data is available in the PCM drivers open callback.

Have you test this yet?

Quoted 3 lines

- Lars

Best Regards,
Bo Shen

#2 lore raw
Quoted 5 lines · Bo Shen

Hi Lars,

Quoted 2 lines · Lars-Peter Clausen

Hi,

Quoted 8 lines
Quoted 5 lines

The dmaengine based pcm driver for atmel calls snd_dmaengine_pcm_open from it's hw_params callback. There is nothing preventing an application calling hw_params more than once. snd_dmaengine_pcm_open allocates a new prtd struct each time it gets called. So in case hw_params is called multiple times we leak memory here.

I use alsa utils and don't meet this issue. Please point out which software you use meet this issue.

I found the issue by looking at the code, but I think any application using the oss compatibility layer of ALSA will trigger this.

Quoted 5 lines
Quoted 4 lines

Is there any specific reason why snd_dmaengine_pcm_open() needs to be called from the hw_params callback and why it can't be called from the open callback?

Quoted 8 lines

This is because dma data setting and usage.

The filter function depends on the data returned by

Quoted 3 lines

snd_soc_dai_get_dma_data(), but as far as I can see the DAI driver calls snd_soc_dai_set_dma_data() from its startup() callback, so the data is available in the PCM drivers open callback.

Have you test this yet?

I don't have the hardware. I just looked at the code again, and it looks like I must have misread it the first time. snd_soc_dai_set_dma_data() is called from the DAI drivers hwparams callback. But the data that gets passed to snd_soc_dai_set_dma_data() doesn't really depend on anything that's only available in the hwparams callback. So the snd_soc_dai_set_dma_data() could easily be move to the DAI driver startup() callback.

- Lars

#3 lore raw

Hi Lars,

Quoted 12 lines · Lars-Peter Clausen
Quoted 11 lines · Bo Shen

Hi Lars,

Quoted 7 lines · Lars-Peter Clausen

Hi,

The dmaengine based pcm driver for atmel calls snd_dmaengine_pcm_open from it's hw_params callback. There is nothing preventing an application calling hw_params more than once. snd_dmaengine_pcm_open allocates a new prtd struct each time it gets called. So in case hw_params is called multiple times we leak memory here.

Quoted 5 lines
Quoted 2 lines

I use alsa utils and don't meet this issue. Please point out which software you use meet this issue.

I found the issue by looking at the code, but I think any application using the oss compatibility layer of ALSA will trigger this.

Thanks for this information.

Quoted 13 lines
Quoted 13 lines
Quoted 5 lines

Is there any specific reason why snd_dmaengine_pcm_open() needs to be called from the hw_params callback and why it can't be called from the open callback?

This is because dma data setting and usage.

The filter function depends on the data returned by

Quoted 3 lines

snd_soc_dai_get_dma_data(), but as far as I can see the DAI driver calls snd_soc_dai_set_dma_data() from its startup() callback, so the data is available in the PCM drivers open callback.

Quoted 8 lines
Quoted 1 line

Have you test this yet?

I don't have the hardware. I just looked at the code again, and it looks like I must have misread it the first time. snd_soc_dai_set_dma_data() is called from the DAI drivers hwparams callback. But the data that gets passed to snd_soc_dai_set_dma_data() doesn't really depend on anything that's only available in the hwparams callback. So the snd_soc_dai_set_dma_data() could easily be move to the DAI driver startup() callback.

I will implement this, and send patch for this.

Thanks again.

Quoted 2 lines

- Lars

Best Regards,
Bo Shen