Use kcalloc instead of kzalloc
cover Use kcalloc instead of kzalloc
These patches use kcalloc instead of kzalloc to allocate array.
Shraddha Barke (4):
Staging: rdma: hfi1: Use kcalloc instead of kzalloc to allocate array
Staging: rdma: ipath: Use kcalloc instead of kzalloc to allocate array
Staging: unisys: Use kcalloc instead of kzalloc to allocate array
Staging: rtl8192e: Use kcalloc instead of kzalloc to allocate array
drivers/staging/rdma/hfi1/diag.c | 5 ++--- drivers/staging/rdma/hfi1/init.c | 14 ++++++++------ drivers/staging/rdma/hfi1/user_sdma.c | 4 ++-- drivers/staging/rdma/ipath/ipath_init_chip.c | 2 +- drivers/staging/rdma/ipath/ipath_qp.c | 2 +- drivers/staging/rdma/ipath/ipath_verbs.c | 2 +- drivers/staging/rtl8192e/rtllib_module.c | 5 ++--- drivers/staging/unisys/visornic/visornic_main.c | 4 ++-- 8 files changed, 19 insertions(+), 19 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/4 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.
--- drivers/staging/rdma/hfi1/diag.c | 5 ++--- drivers/staging/rdma/hfi1/init.c | 14 ++++++++------ drivers/staging/rdma/hfi1/user_sdma.c | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/staging/rdma/hfi1/diag.c +2 -3
@@ -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 ;
drivers/staging/rdma/hfi1/init.c +8 -6
@@ -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
drivers/staging/rdma/hfi1/user_sdma.c +2 -2
@@ -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 ;
Signature · 1 line
2.1.4
PATCH 2/4 Staging: rdma: ipath: Use kcalloc instead of kzalloc to allocate array
In reply to Shraddha BarkeThe 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.
--- drivers/staging/rdma/ipath/ipath_init_chip.c | 2 +- drivers/staging/rdma/ipath/ipath_qp.c | 2 +- drivers/staging/rdma/ipath/ipath_verbs.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rdma/ipath/ipath_init_chip.c +1 -1
@@ -264,7 +264,7 @@ static int init_chip_first(struct ipath_devdata *dd)* Allocate full portcnt array, rather than just cfgports, because * cleanup iterates across all possible ports. */ - dd->ipath_pd =kzalloc (sizeof (*dd->ipath_pd) * dd->ipath_portcnt, + dd->ipath_pd =kcalloc (dd->ipath_portcnt,sizeof (*dd->ipath_pd),GFP_KERNEL );if (!dd->ipath_pd) {
drivers/staging/rdma/ipath/ipath_qp.c +1 -1
@@ -1027,7 +1027,7 @@ int ipath_init_qp_table(struct ipath_ibdev *idev, int size) idev->qp_table.last =1 ;/* QPN 0 and 1 are special. */ idev->qp_table.max = size; idev->qp_table.nmaps =1 ; - idev->qp_table.table =kzalloc (size *sizeof (*idev->qp_table.table), + idev->qp_table.table =kcalloc (size,sizeof (*idev->qp_table.table),GFP_KERNEL );if (idev->qp_table.table ==NULL ) { ret = -ENOMEM ;
drivers/staging/rdma/ipath/ipath_verbs.c +1 -1
@@ -2059,7 +2059,7 @@ int ipath_register_ib_device(struct ipath_devdata *dd)* the LKEY). The remaining bits act as a generation number or tag. */ idev->lk_table.max =1 << ib_ipath_lkey_table_size; - idev->lk_table.table =kzalloc (idev->lk_table.max * + idev->lk_table.table =kcalloc (idev->lk_table.max,sizeof (*idev->lk_table.table),GFP_KERNEL );if (idev->lk_table.table ==NULL ) {
Signature · 1 line
2.1.4
PATCH 3/4 Staging: unisys: Use kcalloc instead of kzalloc to allocate array
In reply to Shraddha BarkeThe 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.
--- drivers/staging/unisys/visornic/visornic_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/unisys/visornic/visornic_main.c +2 -2
@@ -1797,8 +1797,8 @@ static int visornic_probe(struct visor_device *dev) goto cleanup_netdev; } - devdata->rcvbuf =kzalloc (sizeof (struct sk_buff *) * - devdata->num_rcv_bufs,GFP_KERNEL ); + devdata->rcvbuf =kcalloc (devdata->num_rcv_bufs, +sizeof (struct sk_buff *),GFP_KERNEL );if (!devdata->rcvbuf) { err = -ENOMEM ; goto cleanup_rcvbuf;
Signature · 1 line
2.1.4
PATCH 4/4 Staging: rtl8192e: Use kcalloc instead of kzalloc to allocate array
In reply to Shraddha BarkeThe 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.
--- drivers/staging/rtl8192e/rtllib_module.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/rtl8192e/rtllib_module.c +2 -3
@@ -59,9 +59,8 @@ static inline int rtllib_networks_allocate(struct rtllib_device *ieee)if (ieee->networks)return 0 ; - ieee->networks =kzalloc ( -MAX_NETWORK_COUNT *sizeof (struct rtllib_network ), -GFP_KERNEL ); + ieee->networks =kcalloc (MAX_NETWORK_COUNT , +sizeof (struct rtllib_network ),GFP_KERNEL );if (!ieee->networks)return -ENOMEM ;
Signature · 1 line
2.1.4