Re: [PATCH] Document kfree and vfree NULL usage

From: Tomas Carnecky
Date: Sat Nov 27 2004 - 18:59:16 EST


Marcel Sebek wrote:
On Sat, Nov 27, 2004 at 04:26:00PM +0200, Pekka Enberg wrote:

Hi,

This patch adds comments for kfree() and vfree() stating that both accept
NULL pointers. I audited vfree() callers and there seems to be lots of
confusion over this in the kernel.

I've cleaned up sound/ directory from "if (x) {k/v}free(x);" and similar
constructions. I'm going to to this for most of the kernel if I found
some time.

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); } }

tom
-
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/