RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()
Subsystems (2)
PATCH 1/1 RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()
sizeof() when applied to a pointer typed expression should gives the size of the pointed data, even if the data is a pointer.
--- drivers/infiniband/hw/mlx5/counters.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/counters.c +2 -2
@@ -456,12 +456,12 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, cnts->num_ext_ppcnt_counters =ARRAY_SIZE (ext_ppcnt_cnts); num_counters +=ARRAY_SIZE (ext_ppcnt_cnts); } - cnts->names =kcalloc (num_counters,sizeof (cnts->names),GFP_KERNEL ); + cnts->names =kcalloc (num_counters,sizeof (*cnts->names),GFP_KERNEL );if (!cnts->names)return -ENOMEM ; cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );if (!cnts->offsets) goto err_names;
Signature · 1 line
2.25.1
Quoted 1 line · Liu Shixin
sizeof()when applied to a pointer typed expression should gives the
gives -> give
Quoted 7 lines
size of the pointed data, even if the data is a pointer.
Signed-off-by Liu Shixin <[email protected]>--- drivers/infiniband/hw/mlx5/counters.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Thanks,
PATCH 1/1 RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()
sizeof() when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.
--- drivers/infiniband/hw/mlx5/counters.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/counters.c +2 -2
@@ -456,12 +456,12 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, cnts->num_ext_ppcnt_counters =ARRAY_SIZE (ext_ppcnt_cnts); num_counters +=ARRAY_SIZE (ext_ppcnt_cnts); } - cnts->names =kcalloc (num_counters,sizeof (cnts->names),GFP_KERNEL ); + cnts->names =kcalloc (num_counters,sizeof (*cnts->names),GFP_KERNEL );if (!cnts->names)return -ENOMEM ; cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );if (!cnts->offsets) goto err_names;
Signature · 1 line
2.25.1
Quoted 13 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>--- drivers/infiniband/hw/mlx5/counters.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/infiniband/hw/mlx5/counters.c +0
-0
drivers/infiniband/hw/mlx5/counters.c static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, · line 459
Quoted 5 lines
drivers/infiniband/hw/mlx5/counters.c +1
-1@@ -456,12 +456,12 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, cnts->num_ext_ppcnt_counters =ARRAY_SIZE (ext_ppcnt_cnts); num_counters +=ARRAY_SIZE (ext_ppcnt_cnts); } - cnts->names =kcalloc (num_counters,sizeof (cnts->names),GFP_KERNEL ); + cnts->names =kcalloc (num_counters,sizeof (*cnts->names),GFP_KERNEL );
This change is correct.
drivers/infiniband/hw/mlx5/counters.c static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, · line 464
Quoted 6 lines
drivers/infiniband/hw/mlx5/counters.c +1
-1if (!cnts->names)return -ENOMEM ; cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );
This is not.
Quoted 6 lines
drivers/infiniband/hw/mlx5/counters.c +0
-1if (!cnts->offsets) goto err_names; --2.25.1
PATCH v2 1/1 RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()
sizeof() when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.
--- drivers/infiniband/hw/mlx5/counters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/counters.c +1 -1
@@ -457,7 +457,7 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, cnts->num_ext_ppcnt_counters =ARRAY_SIZE (ext_ppcnt_cnts); num_counters +=ARRAY_SIZE (ext_ppcnt_cnts); } - cnts->names =kcalloc (num_counters,sizeof (cnts->names),GFP_KERNEL ); + cnts->names =kcalloc (num_counters,sizeof (*cnts->names),GFP_KERNEL );if (!cnts->names)return -ENOMEM ;
Signature · 1 line
2.25.1
Quoted 8 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>--- drivers/infiniband/hw/mlx5/counters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks,
Jason Gunthorpe
maintainerQuoted 5 lines · Leon Romanovsky
Quoted 4 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>
Needs a fixes line
Quoted 8 lines
drivers/infiniband/hw/mlx5/counters.c static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, · line 464
Quoted 6 lines
drivers/infiniband/hw/mlx5/counters.c +1
-1if (!cnts->names)return -ENOMEM ; cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );This is not.
Why not?
Jason
Quoted 12 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky
Quoted 4 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>Needs a fixes line
Quoted 3 lines
Quoted 3 lines
drivers/infiniband/hw/mlx5/counters.c +0
-0if (!cnts->names)return -ENOMEM ;
Quoted 7 lines
Quoted 5 lines
drivers/infiniband/hw/mlx5/counters.c static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, · line 464
Quoted 3 lines
drivers/infiniband/hw/mlx5/counters.c +1
-1cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );This is not.
Why not?
cnts->offsets is array of pointers that we will set later. The "sizeof(*cnts->offsets)" will return the size of size_t, while we need to get "size_t *".
Thanks
Quoted 2 lines
Jason
Quoted 19 lines · Leon Romanovsky
Quoted 18 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky
Quoted 4 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>Needs a fixes line
Quoted 8 lines
drivers/infiniband/hw/mlx5/counters.c static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, · line 464
Quoted 6 lines
drivers/infiniband/hw/mlx5/counters.c +1
-1if (!cnts->names)return -ENOMEM ; cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );This is not.
Quoted 5 lines
Quoted 1 line
Why not?
cnts->offsetsis array of pointers that we will set later. The "sizeof(*cnts->offsets)" will return the size ofsize_t, while we need to get "size_t*".
Then why isn't a pointer to size **?
Something is rotten here
Jason
Quoted 22 lines · Jason Gunthorpe
Quoted 21 lines · Leon Romanovsky
Quoted 19 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky
Quoted 4 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>Needs a fixes line
Quoted 8 lines
drivers/infiniband/hw/mlx5/counters.c static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, · line 464
Quoted 6 lines
drivers/infiniband/hw/mlx5/counters.c +1
-1if (!cnts->names)return -ENOMEM ; cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );This is not.
Why not?
Quoted 7 lines
Quoted 3 lines
cnts->offsetsis array of pointers that we will set later. The "sizeof(*cnts->offsets)" will return the size ofsize_t, while we need to get "size_t*".Then why isn't a pointer to size **?
Something is rotten here
No problem, I'll check.
Quoted 2 lines
Jason
Quoted 18 lines · Leon Romanovsky
Quoted 17 lines · Jason Gunthorpe
Quoted 16 lines · Leon Romanovsky
Quoted 15 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky
Quoted 4 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>Needs a fixes line
Quoted 7 lines
drivers/infiniband/hw/mlx5/counters.c static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, · line 464
Quoted 6 lines
drivers/infiniband/hw/mlx5/counters.c +1
-1if (!cnts->names)return -ENOMEM ; cnts->offsets =kcalloc (num_counters, -sizeof (cnts->offsets),GFP_KERNEL ); +sizeof (*cnts->offsets),GFP_KERNEL );This is not.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Why not?
cnts->offsetsis array of pointers that we will set later. The "sizeof(*cnts->offsets)" will return the size ofsize_t, while we need to get "size_t*".Then why isn't a pointer to size **?
Something is rotten here
No problem, I'll check.
I think cnts->offsets is an array pointer whose element is size_t rathen than pointer, so the patch description does not correspond.
And I think it should be modified to sizeof(*cnts->offsets) with other description.
Quoted 4 lines
Quoted 2 lines
Jason
.
Quoted 23 lines · Liu Shixin
Quoted 22 lines · Leon Romanovsky
Quoted 21 lines · Jason Gunthorpe
Quoted 20 lines · Leon Romanovsky
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky
Quoted 4 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should give the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>Needs a fixes line
Quoted 8 lines
Quoted 7 lines
Review
Quoted 6 lines
(quoted diff) +1
-1if (!cnts->names) return -ENOMEM; cnts->offsets = kcalloc(num_counters, - sizeof(cnts->offsets), GFP_KERNEL); + sizeof(*cnts->offsets), GFP_KERNEL);This is not.
Why not?
cnts->offsetsis array of pointers that we will set later. The "sizeof(*cnts->offsets)" will return the size ofsize_t, while we need to get "size_t*".
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Then why isn't a pointer to size **?
Something is rotten here
No problem, I'll check.
I think
cnts->offsetsis an array pointer whose element issize_trathen than pointer, so the patch description does not correspond.
And I think it should be modified tosizeof(*cnts->offsets)with other description.
Sorry for me being wrong, you are right.
Thanks
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Jason
.
Jason Gunthorpe
maintainerQuoted 7 lines · Liu Shixin
sizeof()when applied to a pointer typed expression should gives the size of the pointed data, even if the data is a pointer.Signed-off-by Liu Shixin <[email protected]>--- drivers/infiniband/hw/mlx5/counters.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied the original version to for-next
Thanks,
Jason