linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: Fix the loop condition in ext4_mb_free_committed_blocks
@ 2008-06-11  3:55 Shen Feng
  2008-06-11 11:34 ` Aneesh Kumar K.V
  2008-06-11 14:23 ` Theodore Tso
  0 siblings, 2 replies; 4+ messages in thread
From: Shen Feng @ 2008-06-11  3:55 UTC (permalink / raw)
  To: linux-ext4, Theodore Tso, Mingming Cao, Andrew Morton


Since md is freed before the do-while checks it,
it's better to change it to while(1).

Signed-off-by: Shen Feng <shen@cn.fujitsu.com>
---
 fs/ext4/mballoc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 42553f6..063f820 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2572,7 +2572,7 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
 		kfree(md);
 		ext4_mb_release_desc(&e4b);
 
-	} while (md);
+	} while (1);
 
 	mb_debug("freed %u blocks in %u structures\n", count, count2);
 }
-- 
1.5.4.5

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

* Re: [PATCH] ext4: Fix the loop condition in ext4_mb_free_committed_blocks
  2008-06-11  3:55 [PATCH] ext4: Fix the loop condition in ext4_mb_free_committed_blocks Shen Feng
@ 2008-06-11 11:34 ` Aneesh Kumar K.V
  2008-06-11 14:23 ` Theodore Tso
  1 sibling, 0 replies; 4+ messages in thread
From: Aneesh Kumar K.V @ 2008-06-11 11:34 UTC (permalink / raw)
  To: Shen Feng; +Cc: linux-ext4, Theodore Tso, Mingming Cao, Andrew Morton

On Wed, Jun 11, 2008 at 11:55:45AM +0800, Shen Feng wrote:
> 
> Since md is freed before the do-while checks it,
> it's better to change it to while(1).
> 
> Signed-off-by: Shen Feng <shen@cn.fujitsu.com>

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

> ---
>  fs/ext4/mballoc.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 42553f6..063f820 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -2572,7 +2572,7 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
>  		kfree(md);
>  		ext4_mb_release_desc(&e4b);
> 
> -	} while (md);
> +	} while (1);
> 
>  	mb_debug("freed %u blocks in %u structures\n", count, count2);
>  }
> -- 
> 1.5.4.5
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] ext4: Fix the loop condition in ext4_mb_free_committed_blocks
  2008-06-11  3:55 [PATCH] ext4: Fix the loop condition in ext4_mb_free_committed_blocks Shen Feng
  2008-06-11 11:34 ` Aneesh Kumar K.V
@ 2008-06-11 14:23 ` Theodore Tso
  2008-06-12  2:57   ` [PATCH V2] " Shen Feng
  1 sibling, 1 reply; 4+ messages in thread
From: Theodore Tso @ 2008-06-11 14:23 UTC (permalink / raw)
  To: Shen Feng; +Cc: linux-ext4, Mingming Cao, Andrew Morton

On Wed, Jun 11, 2008 at 11:55:45AM +0800, Shen Feng wrote:
> 
> Since md is freed before the do-while checks it,
> it's better to change it to while(1).

This actually isn't a bug, since there is no problem checking a
pointer that has been freed; its only *dereferencing* a pointer which
is bad.  That being said, md is never NULL at the end of the loop,
since in the middle of the loop is the only break condition:

	if (md == NULL)
		break;

So the patch saves a tiny amount of compiled code, but it isn't really
a fix in any way.

That being said, if we're going to make this sort of change, my
preference would be to use the more common C idiom:

	while (1) {
	      ...
	}

as opposed to

	do {
	      ...
	} while (1);

The former makes it quite clear that any exit from the loop is not
going to be coming from loop construct itself, but from any embedded
break statements inside the loop construct

Regards,

						- Ted

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

* [PATCH V2] ext4: Fix the loop condition in ext4_mb_free_committed_blocks
  2008-06-11 14:23 ` Theodore Tso
@ 2008-06-12  2:57   ` Shen Feng
  0 siblings, 0 replies; 4+ messages in thread
From: Shen Feng @ 2008-06-12  2:57 UTC (permalink / raw)
  To: Theodore Tso; +Cc: linux-ext4, Mingming Cao, Andrew Morton


>> Since md is freed before the do-while checks it,
>> it's better to change it to while(1).
> 
> This actually isn't a bug, since there is no problem checking a
> pointer that has been freed; its only *dereferencing* a pointer which
> is bad.  That being said, md is never NULL at the end of the loop,
> since in the middle of the loop is the only break condition:
> 
> 	if (md == NULL)
> 		break;
> 
> So the patch saves a tiny amount of compiled code, but it isn't really
> a fix in any way.
> 
> That being said, if we're going to make this sort of change, my
> preference would be to use the more common C idiom:
> 
> 	while (1) {
> 	      ...
> 	}
> 
> as opposed to
> 
> 	do {
> 	      ...
> 	} while (1);
> 
> The former makes it quite clear that any exit from the loop is not
> going to be coming from loop construct itself, but from any embedded
> break statements inside the loop construct
> 

Yes. You are right. Revise the patch as you suggested.

Signed-off-by: Shen Feng <shen@cn.fujitsu.com>
---
 fs/ext4/mballoc.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index c9900aa..bd6cf22 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2521,7 +2521,7 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
 		return;
 
 	/* there is committed blocks to be freed yet */
-	do {
+	while (1) {
 		/* get next array of blocks */
 		md = NULL;
 		spin_lock(&sbi->s_md_lock);
@@ -2561,7 +2561,7 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
 		kfree(md);
 		ext4_mb_release_desc(&e4b);
 
-	} while (md);
+	}
 
 	mb_debug("freed %u blocks in %u structures\n", count, count2);
 }
-- 1.5.4.5 

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

end of thread, other threads:[~2008-06-12  3:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-11  3:55 [PATCH] ext4: Fix the loop condition in ext4_mb_free_committed_blocks Shen Feng
2008-06-11 11:34 ` Aneesh Kumar K.V
2008-06-11 14:23 ` Theodore Tso
2008-06-12  2:57   ` [PATCH V2] " Shen Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).