Question

I am trying to debug a kernel code, because of a "scheduling while in atomic" that is crashing my system. In some point of an actual kernel module I added a line for calling a function defined in another kernel module (this one made by me). The call is:

mycallback(svc, skb);

And mycallback() function returns int. So I have 2 questions:

  1. Is it safe to call a non-void function inside the kernel without asigning its result to a variable?

  2. If the code where mycallback() is called would be spin_locked or something like that, would it be safe? Would it be spin_locked/atomic or I might sleep and compromise the kernel?

Was it helpful?

Solution

Is it safe to call a non-void function inside the kernel without asigning its result to a variable?

Yes.

If the code where mycallback() is called would be spin_locked or something like that, would it be safe? Would it be spin_locked/atomic or I might sleep and compromise the kernel?

If the code that calls mycallback() can hold a spinlock, mycallback() must not call any functions that can sleep. If you do try to sleep while holding a spinlock, you will see the "Scheduling while atomic" crash that you've described.

Potentially sleeping functions include copy_to_user(), copy_from_user(), kmalloc() (without the GFP_ATOMIC flag), mutex_lock() and a lot more beside.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top