Linux kernel has a optimized way to check for validity of conditions. They are likely(x) and unlikely(x) defined macros.
#define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0)
This may see little confuse, but the general ideal that I keep in mind is: likely(x) means “I expect x to be true”, and unlikely(x) means “I expect x to be false”. This helps me when I use these macros. I’m not sure how much these bultin macros can improve performance, but as we can see in many piece of kernel’s code, I think they can help a lot. (I’m quite newbie in kernel programming :))