Re: Style question: Should one check for NULL pointers?

Ingo Oeser
2003-07-13T22:43:26Z

Hi,

On Thu, Jul 10, 2003 at 04:28:09PM -0400, Alan Stern wrote:
> There are many places in the kernel where a function checks whether a
> pointers it has been given is NULL. Now sometimes this makes perfect
> sense because the function's description explicitly says that a NULL
> pointer argument is valid. But in many, many cases (maybe even the
> majority) it is nothing more than paranoia: the pointer can never be NULL
> in a properly functioning system.

There are many meanings of NULL.

a) NULL -> I don't know
Reaction: Ok, then do a generic/default variant.

b) NULL -> failure in caller passed down to us.
Reaction: Pass it on, return -EINVAL or ignore the call

c) NULL -> failure in API (argument can't be NULL)
Reaction: BUG_ON()

...

So the answer isn't only taste, it's a matter of simplicity and
roboustness.

Regards

Ingo Oeser