I have a question about assert()
in Linux: can I use it in the kernel?
If no, what techniques do you usually use if, for example I don\'t want to enter NULL
No. Unless you're working on the kernel core and rather on a module, you should do your best to never crash (technically, abort()
) the kernel. If you don't want to use a NULL pointer, just don't do it. Check it before using it, and produce an error log if it is.
The closest thing you might want to do if you're actually handling a fatal case is the panic() function or the BUG_ON
and WARN_ON
macros, which will abort execution and produce diagnostic messages, a stack trace and a list of modules.