Skip to contentSkip to conversation

RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

PATCH In review Liu Shixin 4 participants 13 messages Sep 17, 2020 – Sep 25, 2020

Subsystems (2)
lore
Share & tools
lore

Liu Shixin

author
#0 lore raw

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
index 145f3cb40ccb..aeeb14ecb3ee 100644
@@ -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
author
#2 lore raw

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
index 145f3cb40ccb..aeeb14ecb3ee 100644
@@ -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
#3 lore raw
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.

---
 drivers/infiniband/hw/mlx5/counters.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/counters.c +0 -0
index 145f3cb40ccb..aeeb14ecb3ee 100644

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 -1
 	if (!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 -1
 	if (!cnts->offsets)
 		goto err_names;
 
--

2.25.1

author
#4 lore raw

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
index 8d77fea0eb48..6f8a8b558070 100644
@@ -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
maintainer
#6 lore raw
In reply to Leon Romanovsky
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.

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 -1
 	if (!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

#7 lore raw
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.

Needs a fixes line

Quoted 3 lines
Quoted 3 lines
drivers/infiniband/hw/mlx5/counters.c +0 -0
 	if (!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 -1
 	cnts->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

#8 lore raw
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.

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 -1
 	if (!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->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 *".

Then why isn't a pointer to size **?

Something is rotten here

Jason

#9 lore raw
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.

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 -1
 	if (!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->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 *".

Then why isn't a pointer to size **?

Something is rotten here

No problem, I'll check.

Quoted 2 lines

Jason

author
#10 lore raw
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.

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 -1
 	if (!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->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 *".

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

.

#11 lore raw
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.

Needs a fixes line

Quoted 8 lines
Quoted 7 lines

Review

Quoted 6 lines
(quoted diff) +1 -1
 	if (!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->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 *".

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

Sorry for me being wrong, you are right.

Thanks

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Jason

.

maintainer
#12 lore raw
In reply to Liu Shixin
Quoted 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.

---
 drivers/infiniband/hw/mlx5/counters.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied the original version to for-next

Thanks,
Jason