All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: Refactor btrfs_lock_cluster() to kill compiler warning
@ 2014-06-22 12:30 Geert Uytterhoeven
  2014-06-23 10:16 ` Miao Xie
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2014-06-22 12:30 UTC (permalink / raw)
  To: Miao Xie, Chris Mason, Josef Bacik
  Cc: linux-btrfs, linux-kernel, Geert Uytterhoeven

fs/btrfs/extent-tree.c: In function ‘btrfs_lock_cluster’:
fs/btrfs/extent-tree.c:6399: warning: ‘used_bg’ may be used uninitialized in this function

  - Replace "again: ... goto again;" by standard C "while (1) { ... }",
  - Move block not processed during the first iteration of the loop to the
    end of the loop, which allows to kill the "locked" variable,

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Please review, compile tested only.
---
 fs/btrfs/extent-tree.c | 42 ++++++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 99c253918208..e151c4a73d7b 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -6397,36 +6397,34 @@ btrfs_lock_cluster(struct btrfs_block_group_cache *block_group,
 		   int delalloc)
 {
 	struct btrfs_block_group_cache *used_bg;
-	bool locked = false;
-again:
+
 	spin_lock(&cluster->refill_lock);
-	if (locked) {
-		if (used_bg == cluster->block_group)
-			return used_bg;
+	while (1) {
+		used_bg = cluster->block_group;
+		if (!used_bg)
+			return NULL;
 
-		up_read(&used_bg->data_rwsem);
-		btrfs_put_block_group(used_bg);
-	}
+		if (used_bg == block_group)
+			return used_bg;
 
-	used_bg = cluster->block_group;
-	if (!used_bg)
-		return NULL;
+		btrfs_get_block_group(used_bg);
 
-	if (used_bg == block_group)
-		return used_bg;
+		if (!delalloc)
+			return used_bg;
 
-	btrfs_get_block_group(used_bg);
+		if (down_read_trylock(&used_bg->data_rwsem))
+			return used_bg;
 
-	if (!delalloc)
-		return used_bg;
+		spin_unlock(&cluster->refill_lock);
+		down_read(&used_bg->data_rwsem);
 
-	if (down_read_trylock(&used_bg->data_rwsem))
-		return used_bg;
+		spin_lock(&cluster->refill_lock);
+		if (used_bg == cluster->block_group)
+			return used_bg;
 
-	spin_unlock(&cluster->refill_lock);
-	down_read(&used_bg->data_rwsem);
-	locked = true;
-	goto again;
+		up_read(&used_bg->data_rwsem);
+		btrfs_put_block_group(used_bg);
+	}
 }
 
 static inline void
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Btrfs: Refactor btrfs_lock_cluster() to kill compiler warning
  2014-06-22 12:30 [PATCH] Btrfs: Refactor btrfs_lock_cluster() to kill compiler warning Geert Uytterhoeven
@ 2014-06-23 10:16 ` Miao Xie
  0 siblings, 0 replies; 2+ messages in thread
From: Miao Xie @ 2014-06-23 10:16 UTC (permalink / raw)
  To: Geert Uytterhoeven, Chris Mason, Josef Bacik; +Cc: linux-btrfs, linux-kernel

On Sun, 22 Jun 2014 14:30:09 +0200, Geert Uytterhoeven wrote:
> fs/btrfs/extent-tree.c: In function ‘btrfs_lock_cluster’:
> fs/btrfs/extent-tree.c:6399: warning: ‘used_bg’ may be used uninitialized in this function
> 
>   - Replace "again: ... goto again;" by standard C "while (1) { ... }",
>   - Move block not processed during the first iteration of the loop to the
>     end of the loop, which allows to kill the "locked" variable,
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Looks good to me.

Reviewed-and-Tested-by: Miao Xie <miaox@cn.fujitsu.com>

> ---
> Please review, compile tested only.
> ---
>  fs/btrfs/extent-tree.c | 42 ++++++++++++++++++++----------------------
>  1 file changed, 20 insertions(+), 22 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 99c253918208..e151c4a73d7b 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -6397,36 +6397,34 @@ btrfs_lock_cluster(struct btrfs_block_group_cache *block_group,
>  		   int delalloc)
>  {
>  	struct btrfs_block_group_cache *used_bg;
> -	bool locked = false;
> -again:
> +
>  	spin_lock(&cluster->refill_lock);
> -	if (locked) {
> -		if (used_bg == cluster->block_group)
> -			return used_bg;
> +	while (1) {
> +		used_bg = cluster->block_group;
> +		if (!used_bg)
> +			return NULL;
>  
> -		up_read(&used_bg->data_rwsem);
> -		btrfs_put_block_group(used_bg);
> -	}
> +		if (used_bg == block_group)
> +			return used_bg;
>  
> -	used_bg = cluster->block_group;
> -	if (!used_bg)
> -		return NULL;
> +		btrfs_get_block_group(used_bg);
>  
> -	if (used_bg == block_group)
> -		return used_bg;
> +		if (!delalloc)
> +			return used_bg;
>  
> -	btrfs_get_block_group(used_bg);
> +		if (down_read_trylock(&used_bg->data_rwsem))
> +			return used_bg;
>  
> -	if (!delalloc)
> -		return used_bg;
> +		spin_unlock(&cluster->refill_lock);
> +		down_read(&used_bg->data_rwsem);
>  
> -	if (down_read_trylock(&used_bg->data_rwsem))
> -		return used_bg;
> +		spin_lock(&cluster->refill_lock);
> +		if (used_bg == cluster->block_group)
> +			return used_bg;
>  
> -	spin_unlock(&cluster->refill_lock);
> -	down_read(&used_bg->data_rwsem);
> -	locked = true;
> -	goto again;
> +		up_read(&used_bg->data_rwsem);
> +		btrfs_put_block_group(used_bg);
> +	}
>  }
>  
>  static inline void
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-23 10:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-22 12:30 [PATCH] Btrfs: Refactor btrfs_lock_cluster() to kill compiler warning Geert Uytterhoeven
2014-06-23 10:16 ` Miao Xie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.