Skip to contentSkip to conversation

Provider/rxe: Allocate rxe/ib objs by calloc

PATCH Applied Shunsuke Mie 4 participants 4 messages Sep 30, 2021 – Oct 6, 2021 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Provider/rxe: Allocate rxe/ib objs by calloc

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().

---
 providers/rxe/rxe.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
providers/rxe/rxe.c +6 -6
index 3533a325..788a1bbd 100644
@@ -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;
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Shunsuke 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().

LGTM,

Thxs, Håkon

Quoted 65 lines

---
providers/rxe/rxe.c | 12 ++++++------

1 file changed, 6 insertions(+), 6 deletions(-)
providers/rxe/rxe.c +6 -6
index 3533a325..788a1bbd 100644
@@ -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;
 
Signature · 1 line
2.17.1
#2 lore raw
In reply to Shunsuke Mie
Quoted 4 lines · Shunsuke 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().

Thanks a lot.

Zhu Yanjun

Quoted 67 lines
---
 providers/rxe/rxe.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
providers/rxe/rxe.c +6 -7
index 3533a325..788a1bbd 100644
@@ -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

#3 lore raw
In reply to Shunsuke Mie
Quoted 9 lines · Shunsuke 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().

---
 providers/rxe/rxe.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Thanks, applied.