diff options
author | Shraddha Barke <shraddha.6596@gmail.com> | 2015-10-09 15:33:26 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-10-13 03:35:21 (GMT) |
commit | 314fcc0d53261a984788d09a1076c17a919504fe (patch) | |
tree | fea5c8109dcbbdebf27632bf57c560960fbe7ebb /drivers | |
parent | 4ecc4a18d987e7e9f4b7eff2bf9215ac02c8a980 (diff) | |
download | linux-314fcc0d53261a984788d09a1076c17a919504fe.tar.xz |
Staging: rdma: hfi1: Use kcalloc instead of kzalloc to allocate array
The advantage of kcalloc is, that will prevent integer overflows which
could result from the multiplication of number of elements and size and
it is also a bit nicer to read.
Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/rdma/hfi1/diag.c | 5 | ||||
-rw-r--r-- | drivers/staging/rdma/hfi1/init.c | 14 | ||||
-rw-r--r-- | drivers/staging/rdma/hfi1/user_sdma.c | 4 |
3 files changed, 12 insertions, 11 deletions
diff --git a/drivers/staging/rdma/hfi1/diag.c b/drivers/staging/rdma/hfi1/diag.c index 3e8d5ac..3d025d7 100644 --- a/drivers/staging/rdma/hfi1/diag.c +++ b/drivers/staging/rdma/hfi1/diag.c @@ -1159,9 +1159,8 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) filter_cmd.opcode, filter_cmd.length, filter_cmd.value_ptr); - filter_value = kzalloc( - filter_cmd.length * sizeof(u8), - GFP_KERNEL); + filter_value = kcalloc(filter_cmd.length, sizeof(u8), + GFP_KERNEL); if (!filter_value) { pr_alert("Not enough memory\n"); ret = -ENOMEM; diff --git a/drivers/staging/rdma/hfi1/init.c b/drivers/staging/rdma/hfi1/init.c index a877eda..84e6213 100644 --- a/drivers/staging/rdma/hfi1/init.c +++ b/drivers/staging/rdma/hfi1/init.c @@ -293,12 +293,14 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt) * The resulting value will be rounded down to the closest * multiple of dd->rcv_entries.group_size. */ - rcd->egrbufs.buffers = kzalloc(sizeof(*rcd->egrbufs.buffers) * - rcd->egrbufs.count, GFP_KERNEL); + rcd->egrbufs.buffers = kcalloc(rcd->egrbufs.count, + sizeof(*rcd->egrbufs.buffers), + GFP_KERNEL); if (!rcd->egrbufs.buffers) goto bail; - rcd->egrbufs.rcvtids = kzalloc(sizeof(*rcd->egrbufs.rcvtids) * - rcd->egrbufs.count, GFP_KERNEL); + rcd->egrbufs.rcvtids = kcalloc(rcd->egrbufs.count, + sizeof(*rcd->egrbufs.rcvtids), + GFP_KERNEL); if (!rcd->egrbufs.rcvtids) goto bail; rcd->egrbufs.size = eager_buffer_size; @@ -1050,8 +1052,8 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra) if (!hfi1_cpulist_count) { u32 count = num_online_cpus(); - hfi1_cpulist = kzalloc(BITS_TO_LONGS(count) * - sizeof(long), GFP_KERNEL); + hfi1_cpulist = kcalloc(BITS_TO_LONGS(count), sizeof(long), + GFP_KERNEL); if (hfi1_cpulist) hfi1_cpulist_count = count; else diff --git a/drivers/staging/rdma/hfi1/user_sdma.c b/drivers/staging/rdma/hfi1/user_sdma.c index 6620262..368878f 100644 --- a/drivers/staging/rdma/hfi1/user_sdma.c +++ b/drivers/staging/rdma/hfi1/user_sdma.c @@ -1050,8 +1050,8 @@ static int pin_vector_pages(struct user_sdma_request *req, unsigned pinned; iovec->npages = num_user_pages(&iovec->iov); - iovec->pages = kzalloc(sizeof(*iovec->pages) * - iovec->npages, GFP_KERNEL); + iovec->pages = kcalloc(iovec->npages, sizeof(*iovec->pages), + GFP_KERNEL); if (!iovec->pages) { SDMA_DBG(req, "Failed page array alloc"); ret = -ENOMEM; |