kfree(NULL)
Quoted 2 lines
Well, we'd have to start by fixing up the janitors that run around taking out the if statements in the callers. :)
You just need to document those two as special. Probably the simplest is to tell the programmer and the compiler in one fell swoop:
if (unlikely(p)) kfree(p);
Or that could be wrapped up in a macro:
#define kfree_likely_null(p) if (unlikely(p)) kfree(p)
Or just mention it to the programmer. A few possible one-line comments:
/* Testing before calling is faster if often NULL, as here. */ /* It's worth the (redundant) test for NULL if it often succeeds */ /* This test saves the call often enough to be worth it. */ /* Test for NULL not necessary, but worth it here */ /* Don't delete NULL test; speed trumps code size here */ /* Very often NULL, so avoid call overhead if possible */ /* kfree(NULL) is legal, but probabilities favor testing here */