Staging: rdma: ipath: Use kcalloc instead of kzalloc to allocate array
authorShraddha Barke <shraddha.6596@gmail.com>
Fri, 9 Oct 2015 15:33:27 +0000 (21:03 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Oct 2015 03:35:21 +0000 (20:35 -0700)
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>
drivers/staging/rdma/ipath/ipath_init_chip.c
drivers/staging/rdma/ipath/ipath_qp.c
drivers/staging/rdma/ipath/ipath_verbs.c

index e95af81ca3caa183909824b6e596f105317c47e2..cec1ebbb86d2bd0b315438ee7db5cf6c7f320939 100644 (file)
@@ -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) {
index face87602dc19f2ea915c0bad57f441123d0c9cb..b2c67662081b2e80fcf9c84b5bd46223f66411ab 100644 (file)
@@ -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;
index 17d9dca65755dd698261b8d87bcd4ad21a9c3740..40f7f059f6b2efb6a3f040237da772e3490cf9e5 100644 (file)
@@ -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) {