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


Groups > linux.kernel > #1595167 > unrolled thread

[PATCH 18/26] IB/ocrdma: Use kcalloc() in three functions

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2017-03-08 14:30 +0100
Last post2017-03-08 16:40 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 18/26] IB/ocrdma: Use kcalloc() in three functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-03-08 14:30 +0100
    Re: [PATCH 18/26] IB/ocrdma: Use kcalloc() in three functions Devesh Sharma <devesh.sharma@broadcom.com> - 2017-03-08 16:40 +0100

#1595167 — [PATCH 18/26] IB/ocrdma: Use kcalloc() in three functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-03-08 14:30 +0100
Subject[PATCH 18/26] IB/ocrdma: Use kcalloc() in three functions
Message-ID<tiJPc-77d-15@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 8 Mar 2017 09:19:47 +0100

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus reuse the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Replace the specification of data types by pointer dereferences
  to make the corresponding size determinations a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index ef670ac1cbe9..330617e1ef75 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -879,9 +879,8 @@ static int ocrdma_build_pbl_tbl(struct ocrdma_dev *dev, struct ocrdma_hw_mr *mr)
 	void *va;
 	dma_addr_t pa;
 
-	mr->pbl_table = kzalloc(sizeof(struct ocrdma_pbl) *
-				mr->num_pbls, GFP_KERNEL);
-
+	mr->pbl_table = kcalloc(mr->num_pbls, sizeof(*mr->pbl_table),
+				GFP_KERNEL);
 	if (!mr->pbl_table)
 		return -ENOMEM;
 
@@ -1362,13 +1361,12 @@ static void ocrdma_set_qp_db(struct ocrdma_dev *dev, struct ocrdma_qp *qp,
 
 static int ocrdma_alloc_wr_id_tbl(struct ocrdma_qp *qp)
 {
-	qp->wqe_wr_id_tbl =
-	    kzalloc(sizeof(*(qp->wqe_wr_id_tbl)) * qp->sq.max_cnt,
-		    GFP_KERNEL);
+	qp->wqe_wr_id_tbl = kcalloc(qp->sq.max_cnt, sizeof(*qp->wqe_wr_id_tbl),
+				    GFP_KERNEL);
 	if (qp->wqe_wr_id_tbl == NULL)
 		return -ENOMEM;
-	qp->rqe_wr_id_tbl =
-	    kzalloc(sizeof(u64) * qp->rq.max_cnt, GFP_KERNEL);
+	qp->rqe_wr_id_tbl = kcalloc(qp->rq.max_cnt, sizeof(*qp->rqe_wr_id_tbl),
+				    GFP_KERNEL);
 	if (qp->rqe_wr_id_tbl == NULL)
 		return -ENOMEM;
 
@@ -1903,8 +1901,9 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd,
 		goto err;
 
 	if (udata == NULL) {
-		srq->rqe_wr_id_tbl = kzalloc(sizeof(u64) * srq->rq.max_cnt,
-			    GFP_KERNEL);
+		srq->rqe_wr_id_tbl = kcalloc(srq->rq.max_cnt,
+					     sizeof(*srq->rqe_wr_id_tbl),
+					     GFP_KERNEL);
 		if (srq->rqe_wr_id_tbl == NULL)
 			goto arm_err;
 
-- 
2.12.0

[toc] | [next] | [standalone]


#1595287

FromDevesh Sharma <devesh.sharma@broadcom.com>
Date2017-03-08 16:40 +0100
Message-ID<tiLR0-8we-15@gated-at.bofh.it>
In reply to#1595167
Acked-By:Devesh Sharma <devesh.sharma@broadcom.com>

On Wed, Mar 8, 2017 at 6:49 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 8 Mar 2017 09:19:47 +0100
>
> * Multiplications for the size determination of memory allocations
>   indicated that array data structures should be processed.
>   Thus reuse the corresponding function "kcalloc".
>
>   This issue was detected by using the Coccinelle software.
>
> * Replace the specification of data types by pointer dereferences
>   to make the corresponding size determinations a bit safer according to
>   the Linux coding style convention.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> index ef670ac1cbe9..330617e1ef75 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> @@ -879,9 +879,8 @@ static int ocrdma_build_pbl_tbl(struct ocrdma_dev *dev, struct ocrdma_hw_mr *mr)
>         void *va;
>         dma_addr_t pa;
>
> -       mr->pbl_table = kzalloc(sizeof(struct ocrdma_pbl) *
> -                               mr->num_pbls, GFP_KERNEL);
> -
> +       mr->pbl_table = kcalloc(mr->num_pbls, sizeof(*mr->pbl_table),
> +                               GFP_KERNEL);
>         if (!mr->pbl_table)
>                 return -ENOMEM;
>
> @@ -1362,13 +1361,12 @@ static void ocrdma_set_qp_db(struct ocrdma_dev *dev, struct ocrdma_qp *qp,
>
>  static int ocrdma_alloc_wr_id_tbl(struct ocrdma_qp *qp)
>  {
> -       qp->wqe_wr_id_tbl =
> -           kzalloc(sizeof(*(qp->wqe_wr_id_tbl)) * qp->sq.max_cnt,
> -                   GFP_KERNEL);
> +       qp->wqe_wr_id_tbl = kcalloc(qp->sq.max_cnt, sizeof(*qp->wqe_wr_id_tbl),
> +                                   GFP_KERNEL);
>         if (qp->wqe_wr_id_tbl == NULL)
>                 return -ENOMEM;
> -       qp->rqe_wr_id_tbl =
> -           kzalloc(sizeof(u64) * qp->rq.max_cnt, GFP_KERNEL);
> +       qp->rqe_wr_id_tbl = kcalloc(qp->rq.max_cnt, sizeof(*qp->rqe_wr_id_tbl),
> +                                   GFP_KERNEL);
>         if (qp->rqe_wr_id_tbl == NULL)
>                 return -ENOMEM;
>
> @@ -1903,8 +1901,9 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd,
>                 goto err;
>
>         if (udata == NULL) {
> -               srq->rqe_wr_id_tbl = kzalloc(sizeof(u64) * srq->rq.max_cnt,
> -                           GFP_KERNEL);
> +               srq->rqe_wr_id_tbl = kcalloc(srq->rq.max_cnt,
> +                                            sizeof(*srq->rqe_wr_id_tbl),
> +                                            GFP_KERNEL);
>                 if (srq->rqe_wr_id_tbl == NULL)
>                         goto arm_err;
>
> --
> 2.12.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web