Skip to contentSkip to conversation

net/mlx4: Use ARRAY_SIZE to get an array's size

PATCH Applied Jason Wang 4 participants 4 messages Aug 17, 2021 – Aug 18, 2021

Subsystems (4)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 net/mlx4: Use ARRAY_SIZE to get an array's size

The ARRAY_SIZE macro is defined to get an array's size which is more compact and more formal in linux source. Thus, we can replace the long sizeof(arr)/sizeof(arr[0]) with the compact ARRAY_SIZE.

---
 drivers/net/ethernet/mellanox/mlx4/qp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/qp.c +1 -1
index 2584bc038f94..b149e601f673 100644
@@ -739,7 +739,7 @@ static void mlx4_cleanup_qp_zones(struct mlx4_dev *dev)
 		int i;
 
 		for (i = 0;
-		     i < sizeof(qp_table->zones_uids)/sizeof(qp_table->zones_uids[0]);
+		     i < ARRAY_SIZE(qp_table->zones_uids);
 		     i++) {
 			struct mlx4_bitmap *bitmap =
 				mlx4_zone_get_bitmap(qp_table->zones,
Signature · 1 line
2.32.0
#1 lore raw
Quoted 3 lines · Jason Wang

The ARRAY_SIZE macro is defined to get an array's size which is more compact and more formal in linux source. Thus, we can replace the long sizeof(arr)/sizeof(arr[0]) with the compact ARRAY_SIZE.

[]

drivers/net/ethernet/mellanox/mlx4/qp.c

Quoted 1 line
drivers/net/ethernet/mellanox/mlx4/qp.c +0 -0

[]

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx4/qp.c +0 -0
@@ -739,7 +739,7 @@ static void mlx4_cleanup_qp_zones(struct mlx4_dev *dev)
  		int i;

  for (i = 0;

drivers/net/ethernet/mellanox/mlx4/qp.c +1 -1
-		     i < sizeof(qp_table->zones_uids)/sizeof(qp_table->zones_uids[0]);
+		     i < ARRAY_SIZE(qp_table->zones_uids);

  i++) {

trivia: could now be a single line

		for (i = 0; i < ARRAY_SIZE(qp_table->zones_uids); i++) {
Reviewed-by
#2 lore raw
Quoted 11 lines · Joe Perches
Quoted 3 lines · Jason Wang

The ARRAY_SIZE macro is defined to get an array's size which is more compact and more formal in linux source. Thus, we can replace the long sizeof(arr)/sizeof(arr[0]) with the compact ARRAY_SIZE.

[]

drivers/net/ethernet/mellanox/mlx4/qp.c

Quoted 1 line
drivers/net/ethernet/mellanox/mlx4/qp.c +0 -0

[]

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/qp.c +0 -0
@@ -739,7 +739,7 @@ static void mlx4_cleanup_qp_zones(struct mlx4_dev *dev)
  		int i;
 
 
Quoted 10 lines

drivers/net/ethernet/mellanox/mlx4/qp.c static void mlx4_cleanup_qp_zones(struct mlx4_dev *dev) · line 743

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/qp.c +1 -1
  		for (i = 0;
-		     i < sizeof(qp_table->zones_uids)/sizeof(qp_table->zones_uids[0]);
+		     i < ARRAY_SIZE(qp_table->zones_uids);
  		     i++) {

trivia: could now be a single line

		for (i = 0; i < ARRAY_SIZE(qp_table->zones_uids); i++) {

I'm fine with both suggestions.

Thanks for your patch.
Tariq

#3 lore raw
In reply to Jason Wang
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Tue, 17 Aug 2021 20:11:06 +0800 you wrote:

The ARRAY_SIZE macro is defined to get an array's size which is more compact and more formal in linux source. Thus, we can replace the long sizeof(arr)/sizeof(arr[0]) with the compact ARRAY_SIZE.

---
 drivers/net/ethernet/mellanox/mlx4/qp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
- net/mlx4: Use ARRAY_SIZE to get an array's size

    https://git.kernel.org/netdev/net-next/c/19b8ece42c56

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html