public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Fix hostap_cs double kfree
@ 2006-03-15  2:39 Eugene Teo
  2006-03-15  3:05 ` Felipe W Damasio
  2006-03-15  3:14 ` Jouni Malinen
  0 siblings, 2 replies; 5+ messages in thread
From: Eugene Teo @ 2006-03-15  2:39 UTC (permalink / raw)
  To: Linux Kernel; +Cc: jkmaline

prism2_config() kfree's twice if kmalloc fails.

Coverity bug #930

Signed-off-by: Eugene Teo <eugene.teo@eugeneteo.net>

--- linux-2.6/drivers/net/wireless/hostap/hostap_cs.c~	2006-03-15 10:05:36.000000000 +0800
+++ linux-2.6/drivers/net/wireless/hostap/hostap_cs.c	2006-03-15 10:24:53.000000000 +0800
@@ -585,8 +585,6 @@
 	parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
 	hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
 	if (parse == NULL || hw_priv == NULL) {
-		kfree(parse);
-		kfree(hw_priv);
 		ret = -ENOMEM;
 		goto failed;
 	}
@@ -783,8 +781,10 @@
 	cs_error(link->handle, last_fn, last_ret);
 
  failed:
-	kfree(parse);
-	kfree(hw_priv);
+	if (parse)
+		kfree(parse);
+	if (hw_priv)
+		kfree(hw_priv);
 	prism2_release((u_long)link);
 	return ret;
 }

-- 
1024D/A6D12F80 print D51D 2633 8DAC 04DB 7265  9BB8 5883 6DAA A6D1 2F80
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

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

* Re: Fix hostap_cs double kfree
  2006-03-15  2:39 Fix hostap_cs double kfree Eugene Teo
@ 2006-03-15  3:05 ` Felipe W Damasio
  2006-03-15  3:55   ` Eugene Teo
  2006-03-15  3:14 ` Jouni Malinen
  1 sibling, 1 reply; 5+ messages in thread
From: Felipe W Damasio @ 2006-03-15  3:05 UTC (permalink / raw)
  To: Eugene Teo; +Cc: Linux Kernel, jkmaline

    Hi Eugene,

Eugene Teo wrote:

>  failed:
>-	kfree(parse);
>-	kfree(hw_priv);
>+	if (parse)
>+		kfree(parse);
>+	if (hw_priv)
>+		kfree(hw_priv);
> 	prism2_release((u_long)link);
> 	return ret;
> }
>  
>
    I don't think those if's are needed, since the kfree code already does:

void kfree(const void *objp)
{
        if (unlikely(!objp))
                return;
...
}

    But if you really want to use it, I suggest using if (likely
(!<pointer>)) there to hint gcc of a possible optimization.

    Cheers,

Felipe Damasio

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

* Re: Fix hostap_cs double kfree
  2006-03-15  2:39 Fix hostap_cs double kfree Eugene Teo
  2006-03-15  3:05 ` Felipe W Damasio
@ 2006-03-15  3:14 ` Jouni Malinen
  2006-03-15  6:44   ` Eugene Teo
  1 sibling, 1 reply; 5+ messages in thread
From: Jouni Malinen @ 2006-03-15  3:14 UTC (permalink / raw)
  To: Eugene Teo; +Cc: Linux Kernel

On Wed, Mar 15, 2006 at 10:39:00AM +0800, Eugene Teo wrote:
> prism2_config() kfree's twice if kmalloc fails.
> 
> Coverity bug #930

Thanks. I'm going through the issues related to Host AP driver in
Coverity database and send a set of patches after some testing.

> --- linux-2.6/drivers/net/wireless/hostap/hostap_cs.c~	2006-03-15 10:05:36.000000000 +0800
> +++ linux-2.6/drivers/net/wireless/hostap/hostap_cs.c	2006-03-15 10:24:53.000000000 +0800
> @@ -585,8 +585,6 @@
>  	parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
>  	hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
>  	if (parse == NULL || hw_priv == NULL) {
> -		kfree(parse);
> -		kfree(hw_priv);
>  		ret = -ENOMEM;
>  		goto failed;
>  	}

This is a valid fix..

> @@ -783,8 +781,10 @@
>  	cs_error(link->handle, last_fn, last_ret);
>  
>   failed:
> -	kfree(parse);
> -	kfree(hw_priv);
> +	if (parse)
> +		kfree(parse);
> +	if (hw_priv)
> +		kfree(hw_priv);
>  	prism2_release((u_long)link);
>  	return ret;

.. but this is not.

-- 
Jouni Malinen                                            PGP id EFC895FA

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

* Re: Fix hostap_cs double kfree
  2006-03-15  3:05 ` Felipe W Damasio
@ 2006-03-15  3:55   ` Eugene Teo
  0 siblings, 0 replies; 5+ messages in thread
From: Eugene Teo @ 2006-03-15  3:55 UTC (permalink / raw)
  To: Felipe W Damasio; +Cc: Linux Kernel, jkmaline

<quote sender="Felipe W Damasio">
> Eugene Teo wrote:
> 
> >  failed:
> >-	kfree(parse);
> >-	kfree(hw_priv);
> >+	if (parse)
> >+		kfree(parse);
> >+	if (hw_priv)
> >+		kfree(hw_priv);
>
>     I don't think those if's are needed, since the kfree code already does:
> 
> void kfree(const void *objp)
> {
>         if (unlikely(!objp))
>                 return;
> ...
> }
> 
>     But if you really want to use it, I suggest using if (likely
> (!<pointer>)) there to hint gcc of a possible optimization.

Ah, thanks for the tip.

Eugene
-- 
1024D/A6D12F80 print D51D 2633 8DAC 04DB 7265  9BB8 5883 6DAA A6D1 2F80
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

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

* Re: Fix hostap_cs double kfree
  2006-03-15  3:14 ` Jouni Malinen
@ 2006-03-15  6:44   ` Eugene Teo
  0 siblings, 0 replies; 5+ messages in thread
From: Eugene Teo @ 2006-03-15  6:44 UTC (permalink / raw)
  To: Linux Kernel; +Cc: Jouni Malinen

<quote sender="Jouni Malinen">
> On Wed, Mar 15, 2006 at 10:39:00AM +0800, Eugene Teo wrote:
> > prism2_config() kfree's twice if kmalloc fails.
> > 
> > Coverity bug #930
> 
> Thanks. I'm going through the issues related to Host AP driver in
> Coverity database and send a set of patches after some testing.

Ok, here's a resend. Thanks.

Eugene

--
prism2_config() kfree's twice if kmalloc fails.

Coverity bug #930

Signed-off-by: Eugene Teo <eugene.teo@eugeneteo.net>

--- linux-2.6/drivers/net/wireless/hostap/hostap_cs.c~	2006-03-15 10:05:36.000000000 +0800
+++ linux-2.6/drivers/net/wireless/hostap/hostap_cs.c	2006-03-15 14:38:54.000000000 +0800
@@ -585,8 +585,6 @@
 	parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
 	hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
 	if (parse == NULL || hw_priv == NULL) {
-		kfree(parse);
-		kfree(hw_priv);
 		ret = -ENOMEM;
 		goto failed;
 	}

-- 
1024D/A6D12F80 print D51D 2633 8DAC 04DB 7265  9BB8 5883 6DAA A6D1 2F80
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

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

end of thread, other threads:[~2006-03-15  6:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-15  2:39 Fix hostap_cs double kfree Eugene Teo
2006-03-15  3:05 ` Felipe W Damasio
2006-03-15  3:55   ` Eugene Teo
2006-03-15  3:14 ` Jouni Malinen
2006-03-15  6:44   ` Eugene Teo

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