public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Tomas Carnecky <tom@dbservice.com>
Cc: Marcel Sebek <sebek64@post.cz>,
	Pekka Enberg <penberg@cs.helsinki.fi>,
	akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Document kfree and vfree NULL usage
Date: Sun, 28 Nov 2004 11:17:17 +1100	[thread overview]
Message-ID: <41A9190D.5020108@yahoo.com.au> (raw)
In-Reply-To: <41A9148E.6070501@dbservice.com>

Tomas Carnecky wrote:
> 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); } }
> 

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.

  reply	other threads:[~2004-11-28  0:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-27 14:26 [PATCH] Document kfree and vfree NULL usage Pekka Enberg
2004-11-27 17:13 ` Marcel Sebek
2004-11-27 19:30   ` Pekka Enberg
2004-11-27 20:43     ` Marcel Sebek
2004-11-27 21:23       ` Phil Oester
2004-11-28  8:05         ` Pekka Enberg
2004-11-28  9:04           ` Marcel Sebek
2004-11-29 14:18             ` [Alsa-devel] " Takashi Iwai
2004-11-27 23:58   ` Tomas Carnecky
2004-11-28  0:17     ` Nick Piggin [this message]
2004-11-28  8:20       ` Pekka Enberg
2004-11-27 23:39 ` John Levon
2004-11-28  8:00   ` Pekka Enberg
  -- strict thread matches above, loose matches on Subject: below --
2004-11-27 22:17 linux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41A9190D.5020108@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    --cc=sebek64@post.cz \
    --cc=tom@dbservice.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox