public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Document kfree and vfree NULL usage
@ 2004-11-27 14:26 Pekka Enberg
  2004-11-27 17:13 ` Marcel Sebek
  2004-11-27 23:39 ` John Levon
  0 siblings, 2 replies; 14+ messages in thread
From: Pekka Enberg @ 2004-11-27 14:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

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.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 slab.c    |    2 ++
 vmalloc.c |    3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

Index: 2.6.10-rc2/mm/slab.c
===================================================================
--- 2.6.10-rc2.orig/mm/slab.c	2004-11-27 14:33:14.000000000 +0200
+++ 2.6.10-rc2/mm/slab.c	2004-11-27 16:12:54.573387384 +0200
@@ -2535,6 +2535,8 @@
  * kfree - free previously allocated memory
  * @objp: pointer returned by kmalloc.
  *
+ * If @objp is NULL, no operation is performed.
+ *
  * Don't free memory not originally allocated by kmalloc()
  * or you will run into trouble.
  */
Index: 2.6.10-rc2/mm/vmalloc.c
===================================================================
--- 2.6.10-rc2.orig/mm/vmalloc.c	2004-11-27 16:13:48.026261312 +0200
+++ 2.6.10-rc2/mm/vmalloc.c	2004-11-27 16:14:04.875699808 +0200
@@ -389,7 +389,8 @@
  *	@addr:		memory base address
  *
  *	Free the virtually contiguous memory area starting at @addr, as
- *	obtained from vmalloc(), vmalloc_32() or __vmalloc().
+ *	obtained from vmalloc(), vmalloc_32() or __vmalloc(). If @addr is
+ *	NULL, no operation is performed.
  *
  *	May not be called in interrupt context.
  */



^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: [PATCH] Document kfree and vfree NULL usage
@ 2004-11-27 22:17 linux
  0 siblings, 0 replies; 14+ messages in thread
From: linux @ 2004-11-27 22:17 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel

>> -	if (mfile) {
>> -		kfree(mfile);
>> -	} else {
>> +	kfree(mfile);
>> +	if (!mfile) {
>>  		snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file);
>>  		return -ENOENT;
>>  	}

> The above change seems to always trigger the ENOENT return, no?

No.  kfree(mfile) doesn't magically change the numerical value of mfile.
Dereferencing it now would be a bad idea, but you can still look at it.

(The ANSI C standard envisions architectures on which just *looking* at
a dangling pointer is illegal, but Linux makes slightly tighter
restrictions.)

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-11-29 14:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox