Commit 314fcc0d authored by Shraddha Barke's avatar Shraddha Barke Committed by Greg Kroah-Hartman

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: default avatarShraddha Barke <shraddha.6596@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4ecc4a18
...@@ -1159,8 +1159,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) ...@@ -1159,8 +1159,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
filter_cmd.opcode, filter_cmd.length, filter_cmd.opcode, filter_cmd.length,
filter_cmd.value_ptr); filter_cmd.value_ptr);
filter_value = kzalloc( filter_value = kcalloc(filter_cmd.length, sizeof(u8),
filter_cmd.length * sizeof(u8),
GFP_KERNEL); GFP_KERNEL);
if (!filter_value) { if (!filter_value) {
pr_alert("Not enough memory\n"); pr_alert("Not enough memory\n");
......
...@@ -293,12 +293,14 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt) ...@@ -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 * The resulting value will be rounded down to the closest
* multiple of dd->rcv_entries.group_size. * multiple of dd->rcv_entries.group_size.
*/ */
rcd->egrbufs.buffers = kzalloc(sizeof(*rcd->egrbufs.buffers) * rcd->egrbufs.buffers = kcalloc(rcd->egrbufs.count,
rcd->egrbufs.count, GFP_KERNEL); sizeof(*rcd->egrbufs.buffers),
GFP_KERNEL);
if (!rcd->egrbufs.buffers) if (!rcd->egrbufs.buffers)
goto bail; goto bail;
rcd->egrbufs.rcvtids = kzalloc(sizeof(*rcd->egrbufs.rcvtids) * rcd->egrbufs.rcvtids = kcalloc(rcd->egrbufs.count,
rcd->egrbufs.count, GFP_KERNEL); sizeof(*rcd->egrbufs.rcvtids),
GFP_KERNEL);
if (!rcd->egrbufs.rcvtids) if (!rcd->egrbufs.rcvtids)
goto bail; goto bail;
rcd->egrbufs.size = eager_buffer_size; rcd->egrbufs.size = eager_buffer_size;
...@@ -1050,8 +1052,8 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra) ...@@ -1050,8 +1052,8 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra)
if (!hfi1_cpulist_count) { if (!hfi1_cpulist_count) {
u32 count = num_online_cpus(); u32 count = num_online_cpus();
hfi1_cpulist = kzalloc(BITS_TO_LONGS(count) * hfi1_cpulist = kcalloc(BITS_TO_LONGS(count), sizeof(long),
sizeof(long), GFP_KERNEL); GFP_KERNEL);
if (hfi1_cpulist) if (hfi1_cpulist)
hfi1_cpulist_count = count; hfi1_cpulist_count = count;
else else
......
...@@ -1050,8 +1050,8 @@ static int pin_vector_pages(struct user_sdma_request *req, ...@@ -1050,8 +1050,8 @@ static int pin_vector_pages(struct user_sdma_request *req,
unsigned pinned; unsigned pinned;
iovec->npages = num_user_pages(&iovec->iov); iovec->npages = num_user_pages(&iovec->iov);
iovec->pages = kzalloc(sizeof(*iovec->pages) * iovec->pages = kcalloc(iovec->npages, sizeof(*iovec->pages),
iovec->npages, GFP_KERNEL); GFP_KERNEL);
if (!iovec->pages) { if (!iovec->pages) {
SDMA_DBG(req, "Failed page array alloc"); SDMA_DBG(req, "Failed page array alloc");
ret = -ENOMEM; ret = -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment