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

Alan Stern (
Sun, 13 Jul 2003 17:42:03 -0400 (EDT)

On Sat, 12 Jul 2003, Horst von Brand wrote:

> Alan Stern <> said:
> [...]
> > But if you look very far through the kernel sources you will see many
> > occurrences of code similar to this:
> >
> > static void release(struct xxx *ptr)
> > {
> > if (!ptr)
> > return;
> > ...
> >
> > I can't see any reason for keeping something like that.
> Just like free(3)

NO! Not just like free(). The documentation for free() explicitly states
that NULL pointers are valid input and result in no action. A
release()-type function, by contrast, is called back from core system code
that guarantees it will always pass a pointer to the currently-registered
owner of the corresponding resource. If the owner were NULL, the
release() function wouldn't have been called in the first place.

Alan Stern

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at