Using assertion in the Linux kernel

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

    Well, dereferencing null pointer will produce an oops, which you can use to find the offending code. Now, if you want to assert() a given condition, you can use

    BUG_ON(condition)
    

    A less lethal mechanism is WARN_ON, which will produce a backtrace without crashing the kernel.

提交回复
热议问题