INFINIBAND: check the return value of kmalloc
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
@@ -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;
Quoted 12 lines · WANG Cong
Don't forget to check the return value of
kmalloc().Signed-off-by WANG Cong <[email protected]>---
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
-0GFP_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
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
@@ -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;
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
8d339921a2cb279457dce79f8a308978e0b41b27Author: WANG Cong <[email protected]> Date: Thu Jul 5 14:40:32 2007 -0700RDMA/cxgb3: Check return of
kmalloc()iniwch_register_device()Signed-off-by WANG Cong <[email protected]>[ Also remove cast from void * return of
kmalloc()as suggested by
Jesper Juhl <[email protected]>. ]Signed-off-by Roland Dreier <[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
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
8d339921a2cb279457dce79f8a308978e0b41b27Author: WANG Cong <[email protected]> Date: Thu Jul 5 14:40:32 2007 -0700
Quoted 7 lines
RDMA/cxgb3: Check return of
kmalloc()iniwch_register_device()Signed-off-by WANG Cong <[email protected]>[ Also remove cast from void * return of
kmalloc()as suggested by
Jesper Juhl <[email protected]>. ]Signed-off-by Roland Dreier <[email protected]>
Very neat. Thanks!
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
8d339921a2cb279457dce79f8a308978e0b41b27Author: WANG Cong <[email protected]> Date: Thu Jul 5 14:40:32 2007 -0700RDMA/cxgb3: Check return of
kmalloc()iniwch_register_device()Signed-off-by WANG Cong <[email protected]>[ Also remove cast from void * return of
kmalloc()as suggested by
Jesper Juhl <[email protected]>. ]Signed-off-by Roland Dreier <[email protected]>drivers/infiniband/hw/cxgb3/iwch_provider.c +4
-3@@ -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;