public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] no need to check for NULL before calling kfree() - fs/ext2/
@ 2005-03-25 22:08 Jesper Juhl
  2005-03-25 22:29 ` linux-os
  0 siblings, 1 reply; 41+ messages in thread
From: Jesper Juhl @ 2005-03-25 22:08 UTC (permalink / raw)
  To: ext2-devel; +Cc: linux-kernel

(please keep me on CC)


kfree() handles NULL fine, to check is redundant.

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>

--- linux-2.6.12-rc1-mm3-orig/fs/ext2/acl.c	2005-03-02 08:38:18.000000000 +0100
+++ linux-2.6.12-rc1-mm3/fs/ext2/acl.c	2005-03-25 22:41:07.000000000 +0100
@@ -194,8 +194,7 @@ ext2_get_acl(struct inode *inode, int ty
 		acl = NULL;
 	else
 		acl = ERR_PTR(retval);
-	if (value)
-		kfree(value);
+	kfree(value);
 
 	if (!IS_ERR(acl)) {
 		switch(type) {
@@ -262,8 +261,7 @@ ext2_set_acl(struct inode *inode, int ty
 
 	error = ext2_xattr_set(inode, name_index, "", value, size, 0);
 
-	if (value)
-		kfree(value);
+	kfree(value);
 	if (!error) {
 		switch(type) {
 			case ACL_TYPE_ACCESS:



^ permalink raw reply	[flat|nested] 41+ messages in thread
* Re: no need to check for NULL before calling kfree() -fs/ext2/
@ 2005-03-31  6:30 P Lavin
  0 siblings, 0 replies; 41+ messages in thread
From: P Lavin @ 2005-03-31  6:30 UTC (permalink / raw)
  To: linux-kernel


Hi Jesper,
I'm sending this mail to mailing list coz in my company we have some
restrictions on o/g mails, Sorry for that...
Lemme ask u smthing, herez the code
     199     sndpkt = (RSI_sndpkt_t *) RSI_MALLOC(sizeof(RSI_sndpkt_t));
     200     sndpkt->buf_list = (RSI_buf_t *) RSI_MALLOC(sizeof(RSI_buf_t));
Here if malloc fails sndpkt->buf_list should be null right ?? & if i
proceed further ..

     201     sndpkt->buf_list->start_addr = buf;
     202     sndpkt->buf_list->length     = length;
Here itself this should crash right ?? But its not crashing here !!! Wt
was happening was

201 sndpkt->buf_list->start_addr = buf; was not getting initailised & wn
we try to access this variable latter
this was crashing.

Actally i'm not checking for return value from kmalloc thatz a mistake,
I'll fix this but why is it not crashing in line # 201 ??

Jesper Juhl wrote:

>On Wed, 30 Mar 2005, P Lavin wrote:
>
>  
>
>>Date: Wed, 30 Mar 2005 12:45:01 +0530
>>From: P Lavin <lavin.p@redpinesignals.com>
>>To: linux-kernel@vger.kernel.org
>>Subject: Re: no need to check for NULL before calling kfree() -fs/ext2/
>>
>>Hi,
>>In my wlan driver module, i allocated some memory using kmalloc in interrupt
>>context, this one failed but its not returning NULL , 
>>    
>>
>
>kmalloc() should always return NULL if the allocation failed.
>
>
>  
>
>>so i was proceeding
>>further everything was going wrong... & finally the kernel crahed. Can any one
>>of you tell me why this is happening ? i cannot use GFP_KERNEL because i'm
>>calling this function from interrupt context & it may block. Any other
>>    
>>
>
>If you need to allocate memory from interrupt context you should be using 
>GFP_ATOMIC (or, if possible, do the allocation earlier in a different 
>context).
>
>
>  
>
I'm using this flag only, this flag does not guarentee mem allocation,
right ??

>>solution for this ?? I'm concerned abt why kmalloc is not returning null if
>>its not a success ??
>>
>>    
>>
>I have no explanation for that, are you sure that's really what's 
>happening?
>
>
>  
>
I'm not checking this , but my explanation is given above.

>>Is it not necessary to check for NULL before calling kfree() ??
>>    
>>
>
>No, it is not nessesary to check for NULL before calling kfree() since 
>kfree() does    
>
>void kfree (const void *objp)
>{
>	... 
>        if (!objp)
>                return;
>	...
>}
>
>So, if you pass kfree() a NULL pointer it deals with it itself, you don't 
>need to check that explicitly before calling kfree() - that's redundant.
>
>
>  
>

Regs,
Lavin

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

end of thread, other threads:[~2005-04-09  2:18 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-25 22:08 [PATCH] no need to check for NULL before calling kfree() - fs/ext2/ Jesper Juhl
2005-03-25 22:29 ` linux-os
2005-03-25 22:44   ` Jesper Juhl
2005-03-26  7:50   ` Pekka Enberg
2005-03-26  8:32   ` Arjan van de Ven
2005-03-26 23:21     ` [PATCH] no need to check for NULL before calling kfree() -fs/ext2/ linux-os
2005-03-26 23:34       ` Marcin Dalecki
2005-03-27  2:00         ` Horst von Brand
2005-03-27  3:18           ` Marcin Dalecki
2005-03-27 22:12         ` linux-os
2005-03-26 23:54       ` Jesper Juhl
2005-03-27  0:05         ` Lee Revell
2005-03-27 10:55           ` Jesper Juhl
2005-03-27 14:56             ` Paul Jackson
2005-03-27 15:12               ` Jan Engelhardt
2005-03-27 17:40                 ` Dave Jones
2005-03-27 18:17                   ` Jan Engelhardt
2005-03-27 19:25                   ` Pekka Enberg
2005-03-27 22:56                   ` Jesper Juhl
2005-03-28  4:53                     ` Paul Jackson
2005-03-30 18:57                       ` Jesper Juhl
2005-03-28  1:20                   ` Horst von Brand
2005-03-28  4:10                   ` Paul Jackson
2005-03-28 12:58                   ` Geert Uytterhoeven
2005-03-29  2:52                   ` Lee Revell
2005-03-29  6:30                     ` Pekka Enberg
2005-03-29  7:06                       ` Jan Engelhardt
2005-03-29  7:24                         ` Pekka J Enberg
2005-03-30  2:44                           ` Paul Jackson
2005-03-30  6:13                             ` Pekka J Enberg
2005-03-30  6:16                               ` Paul Jackson
2005-03-30  7:15                               ` P Lavin
2005-03-30 14:20                                 ` Jesper Juhl
2005-03-30 19:10                             ` Jesper Juhl
2005-04-09  2:21                               ` Jesper Juhl
2005-03-28  4:07                 ` [PATCH] " Paul Jackson
2005-03-27  8:45       ` Arjan van de Ven
2005-03-27 12:51         ` Denis Vlasenko
2005-03-27 14:28           ` Arjan van de Ven
2005-03-27 23:13         ` [PATCH] no need to check for NULL before calling kfree()-fs/ext2/ linux-os
  -- strict thread matches above, loose matches on Subject: below --
2005-03-31  6:30 no need to check for NULL before calling kfree() -fs/ext2/ P Lavin

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