[alsa-devel] Allocating DMA buffer for non-PCM

Takashi Iwai tiwai at suse.de
Thu Feb 14 18:14:00 CET 2013


At Thu, 14 Feb 2013 18:03:53 +0100,
Adrian Knoth wrote:
> 
> Hi!
> 
> Would you say that the following is the proper way to allocate a DMA
> buffer used to hold level data?
> 
> struct hdspm {
> 	struct pci_dev *pci;	/* and an pci info */
> 	struct snd_dma_buffer dmaLevelBuffer;
> 	u32 *level_buffer;	/* suitably aligned address */
>     [..]
> }
> 
> 	/* allocate level buffer */
> 	err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG,
> 			snd_dma_pci_data(hdspm->pci),
> 			MADIFX_LEVEL_BUFFER_SIZE, &hdspm->dmaLevelBuffer);
> 	if (err < 0) {
>     /* error */ [..]
>     }
> 
>     hdspm->level_buffer = snd_sgbuf_get_ptr(&(hdspm->dmaLevelBuffer), 0);

hdspm->level_buffer = (u32*)hdspm.dmaLevelBuffer.area;

> 	memset(hdspm->level_buffer, 0, MADIFX_LEVEL_BUFFER_SIZE);
> 
> 
> This used to work on my development machine (kernel 3.6.x), but now a
> kernel 3.2.0 user reports a NULL pointer dereference of
> hdspm->level_buffer, so apparently, snd_sgbuf_get_ptr() returned NULL
> for him.

What's level_buffer?  Is a SG-buffer for the audio stream?

> How could this possibly happen?

A wrong usage :)


Takashi

> Am I missing something? Better use
> SNDRV_DMA_TYPE_DEV instead?
> 
> 
> 
> TIA
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel at alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 


More information about the Alsa-devel mailing list