Table of Contents
Many functions in the kernel sleep (ie. call schedule()) directly or indirectly: you can never call them while holding a spinlock, or with preemption disabled. This also means you need to be in user context: calling them from an interrupt is illegal.
The most common ones are listed below, but you usually have to read the code to find out if other calls are safe. If everyone else who calls it can sleep, you probably need to be able to sleep, too. In particular, registration and deregistration functions usually expect to be called from user context, and can sleep.
Accesses to userspace:
copy_from_user()
copy_to_user()
get_user()
put_user()
kmalloc(GFP_KERNEL)
mutex_lock_interruptible()
and
mutex_lock()
There is a mutex_trylock()
which does not
sleep. Still, it must not be used inside interrupt context since
its implementation is not safe for that.
mutex_unlock()
will also never sleep.
It cannot be used in interrupt context either since a mutex
must be released by the same task that acquired it.