From: Shen Feng <shen@cn.fujitsu.com>
To: Theodore Tso <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org, Mingming Cao <cmm@us.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH V2] ext4: Fix the loop condition in ext4_mb_free_committed_blocks
Date: Thu, 12 Jun 2008 10:57:05 +0800 [thread overview]
Message-ID: <48509081.7070103@cn.fujitsu.com> (raw)
In-Reply-To: <20080611142356.GL8397@mit.edu>
>> 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
prev parent reply other threads:[~2008-06-12 3:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Shen Feng [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48509081.7070103@cn.fujitsu.com \
--to=shen@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=cmm@us.ibm.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.