All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc
@ 2021-09-30 11:35 Shunsuke Mie
  2021-09-30 12:41 ` Haakon Bugge
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Shunsuke Mie @ 2021-09-30 11:35 UTC (permalink / raw)
  To: Zhu Yanjun; +Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, linux-kernel, mie

Some rxe/ib objects are allocated by malloc() and initialize manually
respectively. To prevent a bug caused by memory uninitialization, this
patch change to use calloc().

Signed-off-by: Shunsuke Mie <mie@igel.co.jp>
---
 providers/rxe/rxe.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c
index 3533a325..788a1bbd 100644
--- a/providers/rxe/rxe.c
+++ b/providers/rxe/rxe.c
@@ -104,7 +104,7 @@ static struct ibv_pd *rxe_alloc_pd(struct ibv_context *context)
 	struct ib_uverbs_alloc_pd_resp resp;
 	struct ibv_pd *pd;
 
-	pd = malloc(sizeof(*pd));
+	pd = calloc(1, sizeof(*pd));
 	if (!pd)
 		return NULL;
 
@@ -225,7 +225,7 @@ static struct ibv_mr *rxe_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
 	struct ib_uverbs_reg_mr_resp resp;
 	int ret;
 
-	vmr = malloc(sizeof(*vmr));
+	vmr = calloc(1, sizeof(*vmr));
 	if (!vmr)
 		return NULL;
 
@@ -382,7 +382,7 @@ static struct ibv_cq *rxe_create_cq(struct ibv_context *context, int cqe,
 	struct urxe_create_cq_resp resp = {};
 	int ret;
 
-	cq = malloc(sizeof(*cq));
+	cq = calloc(1, sizeof(*cq));
 	if (!cq)
 		return NULL;
 
@@ -594,7 +594,7 @@ static struct ibv_srq *rxe_create_srq(struct ibv_pd *pd,
 	struct urxe_create_srq_resp resp;
 	int ret;
 
-	srq = malloc(sizeof(*srq));
+	srq = calloc(1, sizeof(*srq));
 	if (srq == NULL)
 		return NULL;
 
@@ -1167,7 +1167,7 @@ static struct ibv_qp *rxe_create_qp(struct ibv_pd *ibpd,
 	struct rxe_qp *qp;
 	int ret;
 
-	qp = malloc(sizeof(*qp));
+	qp = calloc(1, sizeof(*qp));
 	if (!qp)
 		goto err;
 
@@ -1659,7 +1659,7 @@ static struct ibv_ah *rxe_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
 		return NULL;
 	}
 
-	ah = malloc(sizeof(*ah));
+	ah = calloc(1, sizeof(*ah));
 	if (ah == NULL)
 		return NULL;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc
  2021-09-30 11:35 [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc Shunsuke Mie
@ 2021-09-30 12:41 ` Haakon Bugge
  2021-09-30 14:39 ` Zhu Yanjun
  2021-10-06  8:13 ` Leon Romanovsky
  2 siblings, 0 replies; 4+ messages in thread
From: Haakon Bugge @ 2021-09-30 12:41 UTC (permalink / raw)
  To: Shunsuke Mie
  Cc: Zhu Yanjun, Doug Ledford, Jason Gunthorpe, OFED mailing list, LKML



> On 30 Sep 2021, at 13:35, Shunsuke Mie <mie@igel.co.jp> wrote:
> 
> Some rxe/ib objects are allocated by malloc() and initialize manually
> respectively. To prevent a bug caused by memory uninitialization, this
> patch change to use calloc().
> 
> Signed-off-by: Shunsuke Mie <mie@igel.co.jp>


LGTM,

Reviewed-by: Håkon Bugge <haakon.bugge@oracle.com>


Thxs, Håkon

> ---
> providers/rxe/rxe.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c
> index 3533a325..788a1bbd 100644
> --- a/providers/rxe/rxe.c
> +++ b/providers/rxe/rxe.c
> @@ -104,7 +104,7 @@ static struct ibv_pd *rxe_alloc_pd(struct ibv_context *context)
> 	struct ib_uverbs_alloc_pd_resp resp;
> 	struct ibv_pd *pd;
> 
> -	pd = malloc(sizeof(*pd));
> +	pd = calloc(1, sizeof(*pd));
> 	if (!pd)
> 		return NULL;
> 
> @@ -225,7 +225,7 @@ static struct ibv_mr *rxe_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
> 	struct ib_uverbs_reg_mr_resp resp;
> 	int ret;
> 
> -	vmr = malloc(sizeof(*vmr));
> +	vmr = calloc(1, sizeof(*vmr));
> 	if (!vmr)
> 		return NULL;
> 
> @@ -382,7 +382,7 @@ static struct ibv_cq *rxe_create_cq(struct ibv_context *context, int cqe,
> 	struct urxe_create_cq_resp resp = {};
> 	int ret;
> 
> -	cq = malloc(sizeof(*cq));
> +	cq = calloc(1, sizeof(*cq));
> 	if (!cq)
> 		return NULL;
> 
> @@ -594,7 +594,7 @@ static struct ibv_srq *rxe_create_srq(struct ibv_pd *pd,
> 	struct urxe_create_srq_resp resp;
> 	int ret;
> 
> -	srq = malloc(sizeof(*srq));
> +	srq = calloc(1, sizeof(*srq));
> 	if (srq == NULL)
> 		return NULL;
> 
> @@ -1167,7 +1167,7 @@ static struct ibv_qp *rxe_create_qp(struct ibv_pd *ibpd,
> 	struct rxe_qp *qp;
> 	int ret;
> 
> -	qp = malloc(sizeof(*qp));
> +	qp = calloc(1, sizeof(*qp));
> 	if (!qp)
> 		goto err;
> 
> @@ -1659,7 +1659,7 @@ static struct ibv_ah *rxe_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
> 		return NULL;
> 	}
> 
> -	ah = malloc(sizeof(*ah));
> +	ah = calloc(1, sizeof(*ah));
> 	if (ah == NULL)
> 		return NULL;
> 
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc
  2021-09-30 11:35 [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc Shunsuke Mie
  2021-09-30 12:41 ` Haakon Bugge
@ 2021-09-30 14:39 ` Zhu Yanjun
  2021-10-06  8:13 ` Leon Romanovsky
  2 siblings, 0 replies; 4+ messages in thread
From: Zhu Yanjun @ 2021-09-30 14:39 UTC (permalink / raw)
  To: Shunsuke Mie; +Cc: Doug Ledford, Jason Gunthorpe, RDMA mailing list, LKML

On Thu, Sep 30, 2021 at 7:35 PM Shunsuke Mie <mie@igel.co.jp> wrote:
>
> Some rxe/ib objects are allocated by malloc() and initialize manually
> respectively. To prevent a bug caused by memory uninitialization, this
> patch change to use calloc().

Thanks a lot.

Zhu Yanjun

>
> Signed-off-by: Shunsuke Mie <mie@igel.co.jp>
> ---
>  providers/rxe/rxe.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c
> index 3533a325..788a1bbd 100644
> --- a/providers/rxe/rxe.c
> +++ b/providers/rxe/rxe.c
> @@ -104,7 +104,7 @@ static struct ibv_pd *rxe_alloc_pd(struct ibv_context *context)
>         struct ib_uverbs_alloc_pd_resp resp;
>         struct ibv_pd *pd;
>
> -       pd = malloc(sizeof(*pd));
> +       pd = calloc(1, sizeof(*pd));
>         if (!pd)
>                 return NULL;
>
> @@ -225,7 +225,7 @@ static struct ibv_mr *rxe_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
>         struct ib_uverbs_reg_mr_resp resp;
>         int ret;
>
> -       vmr = malloc(sizeof(*vmr));
> +       vmr = calloc(1, sizeof(*vmr));
>         if (!vmr)
>                 return NULL;
>
> @@ -382,7 +382,7 @@ static struct ibv_cq *rxe_create_cq(struct ibv_context *context, int cqe,
>         struct urxe_create_cq_resp resp = {};
>         int ret;
>
> -       cq = malloc(sizeof(*cq));
> +       cq = calloc(1, sizeof(*cq));
>         if (!cq)
>                 return NULL;
>
> @@ -594,7 +594,7 @@ static struct ibv_srq *rxe_create_srq(struct ibv_pd *pd,
>         struct urxe_create_srq_resp resp;
>         int ret;
>
> -       srq = malloc(sizeof(*srq));
> +       srq = calloc(1, sizeof(*srq));
>         if (srq == NULL)
>                 return NULL;
>
> @@ -1167,7 +1167,7 @@ static struct ibv_qp *rxe_create_qp(struct ibv_pd *ibpd,
>         struct rxe_qp *qp;
>         int ret;
>
> -       qp = malloc(sizeof(*qp));
> +       qp = calloc(1, sizeof(*qp));
>         if (!qp)
>                 goto err;
>
> @@ -1659,7 +1659,7 @@ static struct ibv_ah *rxe_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
>                 return NULL;
>         }
>
> -       ah = malloc(sizeof(*ah));
> +       ah = calloc(1, sizeof(*ah));
>         if (ah == NULL)
>                 return NULL;
>
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc
  2021-09-30 11:35 [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc Shunsuke Mie
  2021-09-30 12:41 ` Haakon Bugge
  2021-09-30 14:39 ` Zhu Yanjun
@ 2021-10-06  8:13 ` Leon Romanovsky
  2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2021-10-06  8:13 UTC (permalink / raw)
  To: Shunsuke Mie
  Cc: Zhu Yanjun, Doug Ledford, Jason Gunthorpe, linux-rdma, linux-kernel

On Thu, Sep 30, 2021 at 08:35:27PM +0900, Shunsuke Mie wrote:
> Some rxe/ib objects are allocated by malloc() and initialize manually
> respectively. To prevent a bug caused by memory uninitialization, this
> patch change to use calloc().
> 
> Signed-off-by: Shunsuke Mie <mie@igel.co.jp>
> ---
>  providers/rxe/rxe.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 

Thanks, applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-06  8:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30 11:35 [PATCH] Provider/rxe: Allocate rxe/ib objs by calloc Shunsuke Mie
2021-09-30 12:41 ` Haakon Bugge
2021-09-30 14:39 ` Zhu Yanjun
2021-10-06  8:13 ` Leon Romanovsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.