public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [-mm Patch] INFINIBAND: check the return value of kmalloc
@ 2007-07-04 16:37 WANG Cong
  2007-07-05  0:00 ` Jesper Juhl
  0 siblings, 1 reply; 6+ messages in thread
From: WANG Cong @ 2007-07-04 16:37 UTC (permalink / raw)
  To: rolandd, mshefty, halr; +Cc: Andrew Morton, LKML


Don't forget to check the return value of kmalloc().

Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>

---

Index: linux-2.6.22-rc6-mm1/drivers/infiniband/hw/cxgb3/iwch_provider.c
===================================================================
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c	2007-06-29 13:18:20.000000000 +0800
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c	2007-07-04 23:17:02.000000000 +0800
@@ -1166,6 +1166,10 @@
 	dev->ibdev.iwcm =
 	    (struct iw_cm_verbs *) kmalloc(sizeof(struct iw_cm_verbs),
 					   GFP_KERNEL);
+	if (!dev->ibdev.iwcm) {
+		ret = -1;
+		goto bail1;
+	}
 	dev->ibdev.iwcm->connect = iwch_connect;
 	dev->ibdev.iwcm->accept = iwch_accept_cr;
 	dev->ibdev.iwcm->reject = iwch_reject_cr;

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

* Re: [-mm Patch] INFINIBAND: check the return value of kmalloc
  2007-07-04 16:37 [-mm Patch] INFINIBAND: check the return value of kmalloc WANG Cong
@ 2007-07-05  0:00 ` Jesper Juhl
  2007-07-05 21:42   ` Roland Dreier
  0 siblings, 1 reply; 6+ messages in thread
From: Jesper Juhl @ 2007-07-05  0:00 UTC (permalink / raw)
  To: WANG Cong; +Cc: rolandd, mshefty, halr, Andrew Morton, LKML

On 04/07/07, WANG Cong <xiyou.wangcong@gmail.com> wrote:
>
> Don't forget to check the return value of kmalloc().
>
> Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
>
> ---
>
> Index: linux-2.6.22-rc6-mm1/drivers/infiniband/hw/cxgb3/iwch_provider.c
> ===================================================================
> --- a/drivers/infiniband/hw/cxgb3/iwch_provider.c       2007-06-29 13:18:20.000000000 +0800
> +++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c       2007-07-04 23:17:02.000000000 +0800
> @@ -1166,6 +1166,10 @@
>         dev->ibdev.iwcm =
>             (struct iw_cm_verbs *) kmalloc(sizeof(struct iw_cm_verbs),

While you are here anyway, why not get rid of that pointless kmalloc()
return value cast at the same time?

>                                            GFP_KERNEL);
> +       if (!dev->ibdev.iwcm) {
> +               ret = -1;
> +               goto bail1;
> +       }
>         dev->ibdev.iwcm->connect = iwch_connect;
>         dev->ibdev.iwcm->accept = iwch_accept_cr;
>         dev->ibdev.iwcm->reject = iwch_reject_cr;


-- 
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

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

* Re: [-mm Patch] INFINIBAND: check the return value of kmalloc
  2007-07-05  0:00 ` Jesper Juhl
@ 2007-07-05 21:42   ` Roland Dreier
  2007-07-05 22:26     ` Jesper Juhl
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Roland Dreier @ 2007-07-05 21:42 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: WANG Cong, rolandd, mshefty, halr, Andrew Morton, LKML,
	Steve Wise

thanks, I added Jesper's suggestion to the original patch and queued
this for 2.6.23:

(Steve, let me know if this looks OK or not to you)

commit 8d339921a2cb279457dce79f8a308978e0b41b27
Author: WANG Cong <xiyou.wangcong@gmail.com>
Date:   Thu Jul 5 14:40:32 2007 -0700

    RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()
    
    Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
    [ Also remove cast from void * return of kmalloc() as suggested by
      Jesper Juhl <jesper.juhl@gmail.com>. ]
    Signed-off-by: Roland Dreier <rolandd@cisco.com>

diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
index e7c2c39..44b6ad2 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
@@ -1163,9 +1163,10 @@ int iwch_register_device(struct iwch_dev *dev)
 	dev->ibdev.post_recv = iwch_post_receive;
 
 
-	dev->ibdev.iwcm =
-	    (struct iw_cm_verbs *) kmalloc(sizeof(struct iw_cm_verbs),
-					   GFP_KERNEL);
+	dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
+	if (!dev->ibdev.icwm)
+		return -ENOMEM;
+
 	dev->ibdev.iwcm->connect = iwch_connect;
 	dev->ibdev.iwcm->accept = iwch_accept_cr;
 	dev->ibdev.iwcm->reject = iwch_reject_cr;

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

* Re: [-mm Patch] INFINIBAND: check the return value of kmalloc
  2007-07-05 21:42   ` Roland Dreier
@ 2007-07-05 22:26     ` Jesper Juhl
  2007-07-06  3:03     ` WANG Cong
  2007-07-09 19:57     ` Steve Wise
  2 siblings, 0 replies; 6+ messages in thread
From: Jesper Juhl @ 2007-07-05 22:26 UTC (permalink / raw)
  To: Roland Dreier
  Cc: WANG Cong, rolandd, mshefty, halr, Andrew Morton, LKML,
	Steve Wise

On 05/07/07, Roland Dreier <rdreier@cisco.com> wrote:
> thanks, I added Jesper's suggestion to the original patch and queued
> this for 2.6.23:
>
> (Steve, let me know if this looks OK or not to you)
>
It certainly looks OK to me :-)


> commit 8d339921a2cb279457dce79f8a308978e0b41b27
> Author: WANG Cong <xiyou.wangcong@gmail.com>
> Date:   Thu Jul 5 14:40:32 2007 -0700
>
>     RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()
>
>     Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
>     [ Also remove cast from void * return of kmalloc() as suggested by
>       Jesper Juhl <jesper.juhl@gmail.com>. ]
>     Signed-off-by: Roland Dreier <rolandd@cisco.com>

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>


-- 
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

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

* Re: [-mm Patch] INFINIBAND: check the return value of kmalloc
  2007-07-05 21:42   ` Roland Dreier
  2007-07-05 22:26     ` Jesper Juhl
@ 2007-07-06  3:03     ` WANG Cong
  2007-07-09 19:57     ` Steve Wise
  2 siblings, 0 replies; 6+ messages in thread
From: WANG Cong @ 2007-07-06  3:03 UTC (permalink / raw)
  To: Roland Dreier
  Cc: Jesper Juhl, rolandd, mshefty, halr, Andrew Morton, LKML,
	Steve Wise

On Thu, Jul 05, 2007 at 02:42:37PM -0700, Roland Dreier wrote:
>thanks, I added Jesper's suggestion to the original patch and queued
>this for 2.6.23:
>
>(Steve, let me know if this looks OK or not to you)
>
>commit 8d339921a2cb279457dce79f8a308978e0b41b27
>Author: WANG Cong <xiyou.wangcong@gmail.com>
>Date:   Thu Jul 5 14:40:32 2007 -0700
>
>    RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()
>    
>    Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
>    [ Also remove cast from void * return of kmalloc() as suggested by
>      Jesper Juhl <jesper.juhl@gmail.com>. ]
>    Signed-off-by: Roland Dreier <rolandd@cisco.com>
>

Very neat. Thanks!


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

* Re: [-mm Patch] INFINIBAND: check the return value of kmalloc
  2007-07-05 21:42   ` Roland Dreier
  2007-07-05 22:26     ` Jesper Juhl
  2007-07-06  3:03     ` WANG Cong
@ 2007-07-09 19:57     ` Steve Wise
  2 siblings, 0 replies; 6+ messages in thread
From: Steve Wise @ 2007-07-09 19:57 UTC (permalink / raw)
  To: Roland Dreier
  Cc: Jesper Juhl, WANG Cong, rolandd, mshefty, halr, Andrew Morton,
	LKML

Looks good.


Roland Dreier wrote:
> thanks, I added Jesper's suggestion to the original patch and queued
> this for 2.6.23:
> 
> (Steve, let me know if this looks OK or not to you)
> 
> commit 8d339921a2cb279457dce79f8a308978e0b41b27
> Author: WANG Cong <xiyou.wangcong@gmail.com>
> Date:   Thu Jul 5 14:40:32 2007 -0700
> 
>     RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()
>     
>     Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
>     [ Also remove cast from void * return of kmalloc() as suggested by
>       Jesper Juhl <jesper.juhl@gmail.com>. ]
>     Signed-off-by: Roland Dreier <rolandd@cisco.com>
> 
> diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
> index e7c2c39..44b6ad2 100644
> --- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
> +++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
> @@ -1163,9 +1163,10 @@ int iwch_register_device(struct iwch_dev *dev)
>  	dev->ibdev.post_recv = iwch_post_receive;
>  
>  
> -	dev->ibdev.iwcm =
> -	    (struct iw_cm_verbs *) kmalloc(sizeof(struct iw_cm_verbs),
> -					   GFP_KERNEL);
> +	dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
> +	if (!dev->ibdev.icwm)
> +		return -ENOMEM;
> +
>  	dev->ibdev.iwcm->connect = iwch_connect;
>  	dev->ibdev.iwcm->accept = iwch_accept_cr;
>  	dev->ibdev.iwcm->reject = iwch_reject_cr;


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

end of thread, other threads:[~2007-07-09 19:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-04 16:37 [-mm Patch] INFINIBAND: check the return value of kmalloc WANG Cong
2007-07-05  0:00 ` Jesper Juhl
2007-07-05 21:42   ` Roland Dreier
2007-07-05 22:26     ` Jesper Juhl
2007-07-06  3:03     ` WANG Cong
2007-07-09 19:57     ` Steve Wise

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