Skip to content

Commit

Permalink
providers/mlx5: Correct argument order in calloc call to fix warning
Browse files Browse the repository at this point in the history
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 <lizhijian@fujitsu.com>
  • Loading branch information
zhijianli88 committed Nov 13, 2024
1 parent 401c0d7 commit 78ddabe
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pyverbs/providers/mlx5/mlx5dv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = <uintptr_t>self.addr
for seg in self.segments:
if isinstance(seg, WqeSeg):
Expand Down

0 comments on commit 78ddabe

Please # to comment.