From 78ddabe9264b46c9c776e8d74144578cf40c964e Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Tue, 12 Nov 2024 17:22:01 +0800 Subject: [PATCH] providers/mlx5: Correct argument order in calloc call to fix warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a compiler warning related to the use of calloc. ``` rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c: In function ‘__pyx_pf_7pyverbs_9providers_4mlx5_6mlx5dv_10WqeCtrlSeg___init__’: rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:48608:53: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args] 48608 | __pyx_v_self->__pyx_base.segment = calloc((sizeof(struct mlx5_wqe_ctrl_seg)), 1); | ^~~~~~ rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:48608:53: note: earlier argument should specify number of elements, later size of each element rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c: In function ‘__pyx_pf_7pyverbs_9providers_4mlx5_6mlx5dv_10WqeDataSeg___init__’: rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:50301:53: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args] 50301 | __pyx_v_self->__pyx_base.segment = calloc((sizeof(struct mlx5_wqe_data_seg)), 1); | ^~~~~~ rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:50301:53: note: earlier argument should specify number of elements, later size of each element ``` The warning was due to transposed arguments in the calloc call, where the number of elements and the size of each element were specified in the wrong order. The correct order for calloc's arguments is: void *calloc(size_t nmemb, size_t size) Signed-off-by: Li Zhijian --- pyverbs/providers/mlx5/mlx5dv.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyverbs/providers/mlx5/mlx5dv.pyx b/pyverbs/providers/mlx5/mlx5dv.pyx index b244dd23b..4df887fa6 100644 --- a/pyverbs/providers/mlx5/mlx5dv.pyx +++ b/pyverbs/providers/mlx5/mlx5dv.pyx @@ -1513,7 +1513,7 @@ cdef class WqeCtrlSeg(WqeSeg): using mlx5dv_set_ctrl_seg, segment values are accessed through the getters/setters. """ - self.segment = calloc(sizeof(dv.mlx5_wqe_ctrl_seg), 1) + self.segment = calloc(1, sizeof(dv.mlx5_wqe_ctrl_seg)) self.set_ctrl_seg(pi, opcode, opmod, qp_num, fm_ce_se, ds, signature, imm) def __str__(self): @@ -1584,7 +1584,7 @@ cdef class WqeDataSeg(WqeSeg): Create a dv.mlx5_wqe_data_seg by allocating it and using dv.mlx5dv_set_data_seg with the values received in init """ - self.segment = calloc(sizeof(dv.mlx5_wqe_data_seg), 1) + self.segment = calloc(1, sizeof(dv.mlx5_wqe_data_seg)) self.set_data_seg(length, lkey, addr) @staticmethod @@ -1646,7 +1646,7 @@ cdef class Wqe(PyverbsCM): self.is_user_addr = False allocation_size = sum(map(lambda x: x.sizeof() if isinstance(x, WqeSeg) else len(x), self.segments)) - self.addr = calloc(allocation_size, 1) + self.addr = calloc(1, allocation_size) addr = self.addr for seg in self.segments: if isinstance(seg, WqeSeg):