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

Ingo Oeser (ingo.oeser@informatik.tu-chemnitz.de)
Mon, 14 Jul 2003 00:53:10 +0200


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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/