diff mbox series

[3/6] btrfs: use for-local variabls that shadow function variables

Message ID 6cebc0c327002303ed351b262396aefbf68cff1b.1716234472.git.dsterba@suse.com (mailing list archive)
State New
Headers show
Series Cleanups and W=2 warning fixes | expand

Commit Message

David Sterba May 20, 2024, 7:52 p.m. UTC
We've started to use for-loop local variables and in a few places this
shadows a function variable. Convert a few cases reported by 'make W=2'.
If applicable also change the style to post-increment, that's the
preferred one.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/qgroup.c  | 11 +++++------
 fs/btrfs/volumes.c |  9 +++------
 fs/btrfs/zoned.c   |  8 +++-----
 3 files changed, 11 insertions(+), 17 deletions(-)

Comments

Naohiro Aota May 21, 2024, 4:13 a.m. UTC | #1
On Mon, May 20, 2024 at 09:52:26PM GMT, David Sterba wrote:
> We've started to use for-loop local variables and in a few places this
> shadows a function variable. Convert a few cases reported by 'make W=2'.
> If applicable also change the style to post-increment, that's the
> preferred one.
> 
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---

LGTM asides from a small nit below.

Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>

>  fs/btrfs/qgroup.c  | 11 +++++------
>  fs/btrfs/volumes.c |  9 +++------
>  fs/btrfs/zoned.c   |  8 +++-----
>  3 files changed, 11 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index fc2a7ea26354..a94a5b87b042 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -3216,7 +3216,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>  			 struct btrfs_qgroup_inherit *inherit)
>  {
>  	int ret = 0;
> -	int i;
>  	u64 *i_qgroups;
>  	bool committing = false;
>  	struct btrfs_fs_info *fs_info = trans->fs_info;
> @@ -3273,7 +3272,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>  		i_qgroups = (u64 *)(inherit + 1);
>  		nums = inherit->num_qgroups + 2 * inherit->num_ref_copies +
>  		       2 * inherit->num_excl_copies;
> -		for (i = 0; i < nums; ++i) {
> +		for (int i = 0; i < nums; i++) {
>  			srcgroup = find_qgroup_rb(fs_info, *i_qgroups);
>  
>  			/*
> @@ -3300,7 +3299,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>  	 */
>  	if (inherit) {
>  		i_qgroups = (u64 *)(inherit + 1);
> -		for (i = 0; i < inherit->num_qgroups; ++i, ++i_qgroups) {
> +		for (int i = 0; i < inherit->num_qgroups; i++, i_qgroups++) {
>  			if (*i_qgroups == 0)
>  				continue;
>  			ret = add_qgroup_relation_item(trans, objectid,
> @@ -3386,7 +3385,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>  		goto unlock;
>  
>  	i_qgroups = (u64 *)(inherit + 1);
> -	for (i = 0; i < inherit->num_qgroups; ++i) {
> +	for (int i = 0; i < inherit->num_qgroups; i++) {
>  		if (*i_qgroups) {
>  			ret = add_relation_rb(fs_info, qlist_prealloc[i], objectid,
>  					      *i_qgroups);
> @@ -3406,7 +3405,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>  		++i_qgroups;
>  	}
>  
> -	for (i = 0; i <  inherit->num_ref_copies; ++i, i_qgroups += 2) {
> +	for (int i = 0; i < inherit->num_ref_copies; i++, i_qgroups += 2) {
>  		struct btrfs_qgroup *src;
>  		struct btrfs_qgroup *dst;
>  
> @@ -3427,7 +3426,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>  		/* Manually tweaking numbers certainly needs a rescan */
>  		need_rescan = true;
>  	}
> -	for (i = 0; i <  inherit->num_excl_copies; ++i, i_qgroups += 2) {
> +	for (int i = 0; i <  inherit->num_excl_copies; i++, i_qgroups += 2) {
                           ^
nit:                       we have double space here for no reason.
Can we just dedup it as well?

>  		struct btrfs_qgroup *src;
>  		struct btrfs_qgroup *dst;
>  
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 7c9d68b1ba69..3f70f727dacf 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5623,8 +5623,6 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
>  	u64 start = ctl->start;
>  	u64 type = ctl->type;
>  	int ret;
> -	int i;
> -	int j;
>  
>  	map = btrfs_alloc_chunk_map(ctl->num_stripes, GFP_NOFS);
>  	if (!map)
> @@ -5639,8 +5637,8 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
>  	map->sub_stripes = ctl->sub_stripes;
>  	map->num_stripes = ctl->num_stripes;
>  
> -	for (i = 0; i < ctl->ndevs; ++i) {
> -		for (j = 0; j < ctl->dev_stripes; ++j) {
> +	for (int i = 0; i < ctl->ndevs; i++) {
> +		for (int j = 0; j < ctl->dev_stripes; j++) {
>  			int s = i * ctl->dev_stripes + j;
>  			map->stripes[s].dev = devices_info[i].dev;
>  			map->stripes[s].physical = devices_info[i].dev_offset +
> @@ -6618,7 +6616,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
>  	struct btrfs_chunk_map *map;
>  	struct btrfs_io_geometry io_geom = { 0 };
>  	u64 map_offset;
> -	int i;
>  	int ret = 0;
>  	int num_copies;
>  	struct btrfs_io_context *bioc = NULL;
> @@ -6764,7 +6761,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
>  		 * For all other non-RAID56 profiles, just copy the target
>  		 * stripe into the bioc.
>  		 */
> -		for (i = 0; i < io_geom.num_stripes; i++) {
> +		for (int i = 0; i < io_geom.num_stripes; i++) {
>  			ret = set_io_stripe(fs_info, logical, length,
>  					    &bioc->stripes[i], map, &io_geom);
>  			if (ret < 0)
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index dde4a0a34037..e9087264f3e3 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -87,9 +87,8 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
>  	bool empty[BTRFS_NR_SB_LOG_ZONES];
>  	bool full[BTRFS_NR_SB_LOG_ZONES];
>  	sector_t sector;
> -	int i;
>  
> -	for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
> +	for (int i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
>  		ASSERT(zones[i].type != BLK_ZONE_TYPE_CONVENTIONAL);
>  		empty[i] = (zones[i].cond == BLK_ZONE_COND_EMPTY);
>  		full[i] = sb_zone_is_full(&zones[i]);
> @@ -121,9 +120,8 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
>  		struct address_space *mapping = bdev->bd_inode->i_mapping;
>  		struct page *page[BTRFS_NR_SB_LOG_ZONES];
>  		struct btrfs_super_block *super[BTRFS_NR_SB_LOG_ZONES];
> -		int i;
>  
> -		for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
> +		for (int i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
>  			u64 zone_end = (zones[i].start + zones[i].capacity) << SECTOR_SHIFT;
>  			u64 bytenr = ALIGN_DOWN(zone_end, BTRFS_SUPER_INFO_SIZE) -
>  						BTRFS_SUPER_INFO_SIZE;
> @@ -144,7 +142,7 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
>  		else
>  			sector = zones[0].start;
>  
> -		for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++)
> +		for (int i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++)
>  			btrfs_release_disk_super(super[i]);
>  	} else if (!full[0] && (empty[1] || full[1])) {
>  		sector = zones[0].wp;
> -- 
> 2.45.0
>
David Sterba May 21, 2024, 1:01 p.m. UTC | #2
On Tue, May 21, 2024 at 04:13:53AM +0000, Naohiro Aota wrote:
> On Mon, May 20, 2024 at 09:52:26PM GMT, David Sterba wrote:
> > We've started to use for-loop local variables and in a few places this
> > shadows a function variable. Convert a few cases reported by 'make W=2'.
> > If applicable also change the style to post-increment, that's the
> > preferred one.
> > 
> > Signed-off-by: David Sterba <dsterba@suse.com>
> > ---
> 
> LGTM asides from a small nit below.
> 
> Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
> 
> >  fs/btrfs/qgroup.c  | 11 +++++------
> >  fs/btrfs/volumes.c |  9 +++------
> >  fs/btrfs/zoned.c   |  8 +++-----
> >  3 files changed, 11 insertions(+), 17 deletions(-)
> > 
> > diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> > index fc2a7ea26354..a94a5b87b042 100644
> > --- a/fs/btrfs/qgroup.c
> > +++ b/fs/btrfs/qgroup.c
> > @@ -3216,7 +3216,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
> >  			 struct btrfs_qgroup_inherit *inherit)
> >  {
> >  	int ret = 0;
> > -	int i;
> >  	u64 *i_qgroups;
> >  	bool committing = false;
> >  	struct btrfs_fs_info *fs_info = trans->fs_info;
> > @@ -3273,7 +3272,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
> >  		i_qgroups = (u64 *)(inherit + 1);
> >  		nums = inherit->num_qgroups + 2 * inherit->num_ref_copies +
> >  		       2 * inherit->num_excl_copies;
> > -		for (i = 0; i < nums; ++i) {
> > +		for (int i = 0; i < nums; i++) {
> >  			srcgroup = find_qgroup_rb(fs_info, *i_qgroups);
> >  
> >  			/*
> > @@ -3300,7 +3299,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
> >  	 */
> >  	if (inherit) {
> >  		i_qgroups = (u64 *)(inherit + 1);
> > -		for (i = 0; i < inherit->num_qgroups; ++i, ++i_qgroups) {
> > +		for (int i = 0; i < inherit->num_qgroups; i++, i_qgroups++) {
> >  			if (*i_qgroups == 0)
> >  				continue;
> >  			ret = add_qgroup_relation_item(trans, objectid,
> > @@ -3386,7 +3385,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
> >  		goto unlock;
> >  
> >  	i_qgroups = (u64 *)(inherit + 1);
> > -	for (i = 0; i < inherit->num_qgroups; ++i) {
> > +	for (int i = 0; i < inherit->num_qgroups; i++) {
> >  		if (*i_qgroups) {
> >  			ret = add_relation_rb(fs_info, qlist_prealloc[i], objectid,
> >  					      *i_qgroups);
> > @@ -3406,7 +3405,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
> >  		++i_qgroups;
> >  	}
> >  
> > -	for (i = 0; i <  inherit->num_ref_copies; ++i, i_qgroups += 2) {
> > +	for (int i = 0; i < inherit->num_ref_copies; i++, i_qgroups += 2) {
> >  		struct btrfs_qgroup *src;
> >  		struct btrfs_qgroup *dst;
> >  
> > @@ -3427,7 +3426,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
> >  		/* Manually tweaking numbers certainly needs a rescan */
> >  		need_rescan = true;
> >  	}
> > -	for (i = 0; i <  inherit->num_excl_copies; ++i, i_qgroups += 2) {
> > +	for (int i = 0; i <  inherit->num_excl_copies; i++, i_qgroups += 2) {
>                            ^
> nit:                       we have double space here for no reason.
> Can we just dedup it as well?

I remember removing it but probably forgot to refresh the patch before
sending.
diff mbox series

Patch

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index fc2a7ea26354..a94a5b87b042 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3216,7 +3216,6 @@  int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 			 struct btrfs_qgroup_inherit *inherit)
 {
 	int ret = 0;
-	int i;
 	u64 *i_qgroups;
 	bool committing = false;
 	struct btrfs_fs_info *fs_info = trans->fs_info;
@@ -3273,7 +3272,7 @@  int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 		i_qgroups = (u64 *)(inherit + 1);
 		nums = inherit->num_qgroups + 2 * inherit->num_ref_copies +
 		       2 * inherit->num_excl_copies;
-		for (i = 0; i < nums; ++i) {
+		for (int i = 0; i < nums; i++) {
 			srcgroup = find_qgroup_rb(fs_info, *i_qgroups);
 
 			/*
@@ -3300,7 +3299,7 @@  int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 	 */
 	if (inherit) {
 		i_qgroups = (u64 *)(inherit + 1);
-		for (i = 0; i < inherit->num_qgroups; ++i, ++i_qgroups) {
+		for (int i = 0; i < inherit->num_qgroups; i++, i_qgroups++) {
 			if (*i_qgroups == 0)
 				continue;
 			ret = add_qgroup_relation_item(trans, objectid,
@@ -3386,7 +3385,7 @@  int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 		goto unlock;
 
 	i_qgroups = (u64 *)(inherit + 1);
-	for (i = 0; i < inherit->num_qgroups; ++i) {
+	for (int i = 0; i < inherit->num_qgroups; i++) {
 		if (*i_qgroups) {
 			ret = add_relation_rb(fs_info, qlist_prealloc[i], objectid,
 					      *i_qgroups);
@@ -3406,7 +3405,7 @@  int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 		++i_qgroups;
 	}
 
-	for (i = 0; i <  inherit->num_ref_copies; ++i, i_qgroups += 2) {
+	for (int i = 0; i < inherit->num_ref_copies; i++, i_qgroups += 2) {
 		struct btrfs_qgroup *src;
 		struct btrfs_qgroup *dst;
 
@@ -3427,7 +3426,7 @@  int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 		/* Manually tweaking numbers certainly needs a rescan */
 		need_rescan = true;
 	}
-	for (i = 0; i <  inherit->num_excl_copies; ++i, i_qgroups += 2) {
+	for (int i = 0; i <  inherit->num_excl_copies; i++, i_qgroups += 2) {
 		struct btrfs_qgroup *src;
 		struct btrfs_qgroup *dst;
 
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 7c9d68b1ba69..3f70f727dacf 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5623,8 +5623,6 @@  static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
 	u64 start = ctl->start;
 	u64 type = ctl->type;
 	int ret;
-	int i;
-	int j;
 
 	map = btrfs_alloc_chunk_map(ctl->num_stripes, GFP_NOFS);
 	if (!map)
@@ -5639,8 +5637,8 @@  static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
 	map->sub_stripes = ctl->sub_stripes;
 	map->num_stripes = ctl->num_stripes;
 
-	for (i = 0; i < ctl->ndevs; ++i) {
-		for (j = 0; j < ctl->dev_stripes; ++j) {
+	for (int i = 0; i < ctl->ndevs; i++) {
+		for (int j = 0; j < ctl->dev_stripes; j++) {
 			int s = i * ctl->dev_stripes + j;
 			map->stripes[s].dev = devices_info[i].dev;
 			map->stripes[s].physical = devices_info[i].dev_offset +
@@ -6618,7 +6616,6 @@  int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 	struct btrfs_chunk_map *map;
 	struct btrfs_io_geometry io_geom = { 0 };
 	u64 map_offset;
-	int i;
 	int ret = 0;
 	int num_copies;
 	struct btrfs_io_context *bioc = NULL;
@@ -6764,7 +6761,7 @@  int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 		 * For all other non-RAID56 profiles, just copy the target
 		 * stripe into the bioc.
 		 */
-		for (i = 0; i < io_geom.num_stripes; i++) {
+		for (int i = 0; i < io_geom.num_stripes; i++) {
 			ret = set_io_stripe(fs_info, logical, length,
 					    &bioc->stripes[i], map, &io_geom);
 			if (ret < 0)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index dde4a0a34037..e9087264f3e3 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -87,9 +87,8 @@  static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
 	bool empty[BTRFS_NR_SB_LOG_ZONES];
 	bool full[BTRFS_NR_SB_LOG_ZONES];
 	sector_t sector;
-	int i;
 
-	for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
+	for (int i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
 		ASSERT(zones[i].type != BLK_ZONE_TYPE_CONVENTIONAL);
 		empty[i] = (zones[i].cond == BLK_ZONE_COND_EMPTY);
 		full[i] = sb_zone_is_full(&zones[i]);
@@ -121,9 +120,8 @@  static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
 		struct address_space *mapping = bdev->bd_inode->i_mapping;
 		struct page *page[BTRFS_NR_SB_LOG_ZONES];
 		struct btrfs_super_block *super[BTRFS_NR_SB_LOG_ZONES];
-		int i;
 
-		for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
+		for (int i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
 			u64 zone_end = (zones[i].start + zones[i].capacity) << SECTOR_SHIFT;
 			u64 bytenr = ALIGN_DOWN(zone_end, BTRFS_SUPER_INFO_SIZE) -
 						BTRFS_SUPER_INFO_SIZE;
@@ -144,7 +142,7 @@  static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
 		else
 			sector = zones[0].start;
 
-		for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++)
+		for (int i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++)
 			btrfs_release_disk_super(super[i]);
 	} else if (!full[0] && (empty[1] || full[1])) {
 		sector = zones[0].wp;