Patchwork [1/4] ext4: fold two if statements into one

login
register
mail settings
Submitter Yongqiang Yang
Date Oct. 26, 2011, 7:11 a.m.
Message ID <1319613112-16807-1-git-send-email-xiaoqiangnk@gmail.com>
Download mbox | patch
Permalink /patch/121863/
State Rejected
Headers show

Comments

Yongqiang Yang - Oct. 26, 2011, 7:11 a.m.
Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
 fs/ext4/extents.c |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)
Theodore Ts'o - Oct. 29, 2011, 1:14 p.m.
On Wed, Oct 26, 2011 at 03:11:49PM +0800, Yongqiang Yang wrote:
> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
> ---
>  fs/ext4/extents.c |   23 +++++++++++------------
>  1 files changed, 11 insertions(+), 12 deletions(-)

Unfortunately this patch is incorrect since it changes when the else
clause would get executed:

       if (a) {
       	   if (b) {
	       ...
	   }
       } else {
           ...
       }

is not the same as:

       if (a && b) {
	   ...
       } else {
           ...
       }

Regards,

					- Ted
--
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

Patch

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index f1ed90b..f887023 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4082,18 +4082,17 @@  got_allocated_blocks:
 		 */
 		reserved_clusters = get_reserved_cluster_alloc(inode,
 						map->m_lblk, allocated);
-		if (map->m_flags & EXT4_MAP_FROM_CLUSTER) {
-			if (reserved_clusters) {
-				/*
-				 * We have clusters reserved for this range.
-				 * But since we are not doing actual allocation
-				 * and are simply using blocks from previously
-				 * allocated cluster, we should release the
-				 * reservation and not claim quota.
-				 */
-				ext4_da_update_reserve_space(inode,
-						reserved_clusters, 0);
-			}
+		if ((map->m_flags & EXT4_MAP_FROM_CLUSTER) &&
+		    reserved_clusters) {
+			/*
+			 * We have clusters reserved for this range.
+			 * But since we are not doing actual allocation
+			 * and are simply using blocks from previously
+			 * allocated cluster, we should release the
+			 * reservation and not claim quota.
+			 */
+			ext4_da_update_reserve_space(inode,
+					reserved_clusters, 0);
 		} else {
 			BUG_ON(allocated_clusters < reserved_clusters);
 			/* We will claim quota for all newly allocated blocks.*/