diff mbox

[22/29] IB/mlx4: Use kmalloc_array() in alloc_proxy_bufs()

Message ID b7f36e89-a3c8-0842-d496-0dbb64fdd73f@users.sourceforge.net (mailing list archive)
State Changes Requested
Headers show

Commit Message

SF Markus Elfring Feb. 18, 2017, 9:12 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 18 Feb 2017 16:56:52 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/infiniband/hw/mlx4/qp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Majd Dibbiny Feb. 19, 2017, 7:53 p.m. UTC | #1
> On Feb 18, 2017, at 11:12 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 18 Feb 2017 16:56:52 +0100
> 
> * A multiplication for the size determination of a memory allocation
>  indicated that an array data structure should be processed.
>  Thus use the corresponding function "kmalloc_array".
> 
>  This issue was detected by using the Coccinelle software.
> 
> * Replace the specification of a data structure by a pointer dereference
>  to make the corresponding size determination a bit safer according to
>  the Linux coding style convention.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/infiniband/hw/mlx4/qp.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
> index 7d76f769233c..11fec4a8fae5 100644
> --- a/drivers/infiniband/hw/mlx4/qp.c
> +++ b/drivers/infiniband/hw/mlx4/qp.c
> @@ -554,9 +554,9 @@ static int alloc_proxy_bufs(struct ib_device *dev, struct mlx4_ib_qp *qp)
> {
>    int i;
> 
> -    qp->sqp_proxy_rcv =
> -        kmalloc(sizeof (struct mlx4_ib_buf) * qp->rq.wqe_cnt,
> -            GFP_KERNEL);
> +    qp->sqp_proxy_rcv = kmalloc_array(qp->rq.wqe_cnt,
> +                      sizeof(*qp->sqp_proxy_rcv),
> +                      GFP_KERNEL);
>    if (!qp->sqp_proxy_rcv)
>        return -ENOMEM;
>    for (i = 0; i < qp->rq.wqe_cnt; i++) {
> -- 
> 2.11.1
> 
> --
> 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
Thanks,
Reviewed-by: Majd Dibbiny
<majd@mellanox.com>

--
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
diff mbox

Patch

diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index 7d76f769233c..11fec4a8fae5 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -554,9 +554,9 @@  static int alloc_proxy_bufs(struct ib_device *dev, struct mlx4_ib_qp *qp)
 {
 	int i;
 
-	qp->sqp_proxy_rcv =
-		kmalloc(sizeof (struct mlx4_ib_buf) * qp->rq.wqe_cnt,
-			GFP_KERNEL);
+	qp->sqp_proxy_rcv = kmalloc_array(qp->rq.wqe_cnt,
+					  sizeof(*qp->sqp_proxy_rcv),
+					  GFP_KERNEL);
 	if (!qp->sqp_proxy_rcv)
 		return -ENOMEM;
 	for (i = 0; i < qp->rq.wqe_cnt; i++) {