Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265105

[PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc

From Geliang Tang <geliangtang@163.com>
Newsgroups linux.kernel
Subject [PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc
Date 2015-11-08 15:30 +0100
Message-ID <qsz8K-1gC-29@gated-at.bofh.it> (permalink)
References <qsz8J-1gC-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Use kmalloc_array instead of kmalloc to allocate memory for an array.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/staging/rdma/amso1100/c2.c          | 6 ++++--
 drivers/staging/rdma/ipath/ipath_file_ops.c | 8 ++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rdma/amso1100/c2.c b/drivers/staging/rdma/amso1100/c2.c
index 35ac536..4e6d24a 100644
--- a/drivers/staging/rdma/amso1100/c2.c
+++ b/drivers/staging/rdma/amso1100/c2.c
@@ -116,7 +116,8 @@ static int c2_tx_ring_alloc(struct c2_ring *tx_ring, void *vaddr,
 	struct c2_element *elem;
 	int i;
 
-	tx_ring->start = kmalloc(sizeof(*elem) * tx_ring->count, GFP_KERNEL);
+	tx_ring->start = kmalloc_array(tx_ring->count, sizeof(*elem),
+				       GFP_KERNEL);
 	if (!tx_ring->start)
 		return -ENOMEM;
 
@@ -165,7 +166,8 @@ static int c2_rx_ring_alloc(struct c2_ring *rx_ring, void *vaddr,
 	struct c2_element *elem;
 	int i;
 
-	rx_ring->start = kmalloc(sizeof(*elem) * rx_ring->count, GFP_KERNEL);
+	rx_ring->start = kmalloc_array(rx_ring->count, sizeof(*elem),
+				       GFP_KERNEL);
 	if (!rx_ring->start)
 		return -ENOMEM;
 
diff --git a/drivers/staging/rdma/ipath/ipath_file_ops.c b/drivers/staging/rdma/ipath/ipath_file_ops.c
index 13c3cd1..6187b84 100644
--- a/drivers/staging/rdma/ipath/ipath_file_ops.c
+++ b/drivers/staging/rdma/ipath/ipath_file_ops.c
@@ -917,15 +917,15 @@ static int ipath_create_user_egr(struct ipath_portdata *pd)
 	chunk = pd->port_rcvegrbuf_chunks;
 	egrperchunk = pd->port_rcvegrbufs_perchunk;
 	size = pd->port_rcvegrbuf_size;
-	pd->port_rcvegrbuf = kmalloc(chunk * sizeof(pd->port_rcvegrbuf[0]),
-				     GFP_KERNEL);
+	pd->port_rcvegrbuf = kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf[0]),
+					   GFP_KERNEL);
 	if (!pd->port_rcvegrbuf) {
 		ret = -ENOMEM;
 		goto bail;
 	}
 	pd->port_rcvegrbuf_phys =
-		kmalloc(chunk * sizeof(pd->port_rcvegrbuf_phys[0]),
-			GFP_KERNEL);
+		kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf_phys[0]),
+			      GFP_KERNEL);
 	if (!pd->port_rcvegrbuf_phys) {
 		ret = -ENOMEM;
 		goto bail_rcvegrbuf;
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-08 15:30 +0100
  [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-08 15:30 +0100
  [PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-08 15:30 +0100
  Re: [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc Ian Abbott <abbotti@mev.co.uk> - 2015-11-09 14:50 +0100
    [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-10 15:50 +0100
      Re: [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc Ian Abbott <abbotti@mev.co.uk> - 2015-11-11 15:10 +0100

csiph-web