Using assertion in the Linux kernel

后端 未结 6 1149
挽巷
挽巷 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:49

    One option would be to use the macro BUG_ON(). It will printk a message, and then panic() (i.e. crash) the kernel.

    http://kernelnewbies.org/KernelHacking-HOWTO/Debugging_Kernel

    Of course, this should only be used as an error handling strategy of last resort (just like assert)...

提交回复
热议问题