Re: [PATCH] Document kfree and vfree NULL usage

From: Pekka Enberg
Date: Sun Nov 28 2004 - 03:22:23 EST


Tomas Carnecky wrote:
> > Isn't 'if (x) { free(x); }' faster than the call to free() with a NULL
> > pointer?
> > What about a macro ?
> > #define fast_free(x) if (x) { free(x); }
> > Or even
> > #define kfree(x) if (x) { _kfree(x); }
> > Or maybe a inline function so it doesn't break existing code.
> > inline void kfree(x) { if (x) { _kfree(x); } }

On Sun, 2004-11-28 at 11:17 +1100, Nick Piggin wrote:
> Well if a NULL parameter is the exceptional case, then you don't want to
> litter the L1 cache with the extra code that will only save a function
> call in rare cases.
>
> And I think it should be the exceptional case, because it shouldn't really
> be used for much other than streamline error handling or cleanup functions
> to cope with failed allocations without adding checks everywhere. If you're
> doing lots of kfree(NULL) as part of normal operation, then that may
> suggest you aren't tracking your memory very well.

Agreed. The drivers also use NULL for optional fields btw. Removing the
redundant checks reduce the size of source and object code so we get
more readable code and smaller memory footprint at the same time (yay!).
Furthermore, we get rid of the _confusion_ over the use of kfree() and
vfree().

Pekka

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