Using assertion in the Linux kernel

后端 未结 6 1156
挽巷
挽巷 2021-02-05 03:09

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

6条回答
  •  梦谈多话
    2021-02-05 03:34

    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.

提交回复
热议问题