Skip to contentSkip to conversation

INFINIBAND: check the return value of kmalloc

PATCH In review WANG Cong 4 participants 6 messages Jul 4, 2007 – Jul 9, 2007 InfiniBand

lore
Share & tools
lore

WANG Cong

author
#0 lore raw

PATCH 1/1 INFINIBAND: check the return value of kmalloc

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

---

drivers/infiniband/hw/cxgb3/iwch_provider.c +4 -0
Index: linux-2.6.22-rc6-mm1/drivers/infiniband/hw/cxgb3/iwch_provider.c
===================================================================
@@ -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;
#1 lore raw
Quoted 12 lines · WANG Cong

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

---

Index: linux-2.6.22-rc6-mm1/drivers/infiniband/hw/cxgb3/iwch_provider.c
===================================================================

drivers/infiniband/hw/cxgb3/iwch_provider.c 2007-07-04 23:17:02.000000000 +0800 line 1167

Quoted 2 lines
drivers/infiniband/hw/cxgb3/iwch_provider.c 2007-07-04 23:17:02.000000000 +0800 renamed from drivers/infiniband/hw/cxgb3/iwch_provider.c 2007-06-29 13:18:20.000000000 +0800 +0 -0
@@ -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?

Quoted 8 lines
drivers/infiniband/hw/cxgb3/iwch_provider.c 2007-07-04 23:17:02.000000000 +0800 renamed from drivers/infiniband/hw/cxgb3/iwch_provider.c 2007-06-29 13:18:20.000000000 +0800 +4 -0
                                           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;
Signature · 3 lines
Jesper Juhl <[email protected]>
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
#2 lore raw

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 <[email protected]>
Date:   Thu Jul 5 14:40:32 2007 -0700

RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()

[ Also remove cast from void * return of kmalloc() as suggested by
Jesper Juhl <[email protected]>. ]

drivers/infiniband/hw/cxgb3/iwch_provider.c +4 -3
index e7c2c39..44b6ad2 100644
@@ -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;
#3 lore raw
Quoted 5 lines · Roland Dreier

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 :-)

Quoted 10 lines

commit 8d339921a2cb279457dce79f8a308978e0b41b27

Author: WANG Cong <[email protected]>
Date:   Thu Jul 5 14:40:32 2007 -0700

RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()

[ Also remove cast from void * return of kmalloc() as suggested by
Jesper Juhl <[email protected]>. ]

Signature · 3 lines
Jesper Juhl <[email protected]>
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
author
#4 lore raw
In reply to Roland Dreier
Quoted 9 lines · Roland Dreier

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 <[email protected]>
Date:   Thu Jul 5 14:40:32 2007 -0700
Quoted 7 lines

RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()

[ Also remove cast from void * return of kmalloc() as suggested by
Jesper Juhl <[email protected]>. ]

Very neat. Thanks!

#5 lore raw
In reply to Roland Dreier

Looks good.

Quoted 34 lines · Roland Dreier

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 <[email protected]>
Date:   Thu Jul 5 14:40:32 2007 -0700

RDMA/cxgb3: Check return of kmalloc() in iwch_register_device()

[ Also remove cast from void * return of kmalloc() as suggested by
Jesper Juhl <[email protected]>. ]

drivers/infiniband/hw/cxgb3/iwch_provider.c +4 -3
index e7c2c39..44b6ad2 100644
@@ -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;