[alsa-devel] Interrupts and kmalloc in alsa modules

Ciaccia ciacciax at yahoo.com
Tue Apr 10 23:34:01 CEST 2007

Hi all,
I am working with an ARM embedded system and I porting
an alsa application to that system. 

Cirrus (the manufacturer of the board) wrote a generic
alsa driver for "their" kernel (a kernel based on the
2.6.8 with some patches) and I ported the module to
the vanilla kernel 2.6.19.

The module works fine (play and capture both work),
but the function that allocates the memory prints a
strange message in the kernel log when the buffers are
allocated (the module calls kmalloc, which prints
"sleeping function called from invalid context" to the

The buffers are allocated when the streams are
started,   not when the module is loaded, I think this
is standard...

The buffers are allocated with the following line:

s->buffers = (audio_buf_t *)
kmalloc(sizeof(audio_buf_t) * s->nbfrags, GFP_KERNEL);

When the line here above is executed, slab.c prints
the error the kernel log. The error comes from the
"might_sleep_if" line:

static inline void
cache_alloc_debugcheck_before(struct kmem_cache
*cachep, gfp_t flags)
	might_sleep_if(flags & __GFP_WAIT);
	kmem_flagcheck(cachep, flags);

Playing with the module, I discovered that if I enable
the interrupts before calling kmalloc, the error
disappears. I wonder if this is correct, or if
something is wrong...

Could someone of you explain to me why I have to
enable the interrupts before calling kmalloc? The
strange thing is that the module never explicitly
turns them off (I attached the file to the mail)

Any help is greatly appreciated ;-)

Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.

More information about the Alsa-devel mailing list