Skip to contentSkip to conversation

ext4: remove unneeded variable.

PATCH In review Namjae Jeon 3 participants 5 messages Nov 11, 2011 – Nov 19, 2011 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: remove unneeded variable.

ret2 is not needed in ext4_flush_completed_IO().

---
 fs/ext4/fsync.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
fs/ext4/fsync.c +1 -4
index 00a2cb7..40397ac 100644
@@ -81,7 +81,6 @@ int ext4_flush_completed_IO(struct inode *inode)
 	struct ext4_inode_info *ei = EXT4_I(inode);
 	unsigned long flags;
 	int ret = 0;
-	int ret2 = 0;
 
 	dump_completed_IO(inode);
 	spin_lock_irqsave(&ei->i_completed_io_lock, flags);
@@ -105,12 +104,10 @@ int ext4_flush_completed_IO(struct inode *inode)
 		 */
 		spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
 		ret = ext4_end_io_nolock(io);
-		if (ret < 0)
-			ret2 = ret;
 		spin_lock_irqsave(&ei->i_completed_io_lock, flags);
 	}
 	spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
-	return (ret2 < 0) ? ret2 : 0;
+	return (ret < 0) ? ret : 0;
 }
 
 /*
Signature · 1 line
1.7.4.4
#1 lore raw

Any feedback for this patch? We surely don't need 'ret2' variable in this code.

Thanks & Regards,
Amit Sahrawat

Quoted 35 lines · Namjae Jeon

ret2 is not needed in ext4_flush_completed_IO().

---
 fs/ext4/fsync.c |    5 +----

 1 files changed, 1 insertions(+), 4 deletions(-)
fs/ext4/fsync.c +1 -5
index 00a2cb7..40397ac 100644
@@ -81,7 +81,6 @@ int ext4_flush_completed_IO(struct inode *inode)
        struct ext4_inode_info *ei = EXT4_I(inode);
        unsigned long flags;
        int ret = 0;
-       int ret2 = 0;
 
        dump_completed_IO(inode);
        spin_lock_irqsave(&ei->i_completed_io_lock, flags);
@@ -105,12 +104,10 @@ int ext4_flush_completed_IO(struct inode *inode)
                 */
                spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
                ret = ext4_end_io_nolock(io);
-               if (ret < 0)
-                       ret2 = ret;
                spin_lock_irqsave(&ei->i_completed_io_lock, flags);
        }
        spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
-       return (ret2 < 0) ? ret2 : 0;
+       return (ret < 0) ? ret : 0;
  }
 
  /*
--
Quoted 3 lines

1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Namjae Jeon
Quoted 2 lines · Namjae Jeon

ret2 is not needed in ext4_flush_completed_IO().

Not needed? I went through the code briefly, and I don't agree.

Quoted 20 lines
---
 fs/ext4/fsync.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
fs/ext4/fsync.c +0 -1
index 00a2cb7..40397ac 100644
@@ -81,7 +81,6 @@ int ext4_flush_completed_IO(struct inode *inode)
 	struct ext4_inode_info *ei = EXT4_I(inode);
 	unsigned long flags;
 	int ret = 0;
-	int ret2 = 0;
 
 	dump_completed_IO(inode);
 	spin_lock_irqsave(&ei->i_completed_io_lock, flags);
@@ -105,12 +104,10 @@ int ext4_flush_completed_IO(struct inode *inode)
 		 */

fs/ext4/fsync.c int ext4_flush_completed_IO(struct inode *inode) · line 111

Quoted 10 lines
fs/ext4/fsync.c +1 -3
 		spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
 		ret = ext4_end_io_nolock(io);
-		if (ret < 0)
-			ret2 = ret;
 		spin_lock_irqsave(&ei->i_completed_io_lock, flags);
 	}
 	spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
-	return (ret2 < 0) ? ret2 : 0;
+	return (ret < 0) ? ret : 0;
 }

Please note that there is a while loop involved here. Which means, that ret2 is used to store the last negative value of ret. And due to the loop, ret can be over-written in the next loop iteration, which we can afford, because we have already stored what we need to save, in ret2. And this ret2 value is used to return appropriate value to the caller.

Thanks,
Srivatsa S. Bhat

#3 lore raw
Quoted 34 lines · Srivatsa S. Bhat
Quoted 2 lines · Namjae Jeon

ret2 is not needed in ext4_flush_completed_IO().

Not needed? I went through the code briefly, and I don't agree.

Quoted 28 lines
---
 fs/ext4/fsync.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
fs/ext4/fsync.c +0 -4
index 00a2cb7..40397ac 100644
@@ -81,7 +81,6 @@ int ext4_flush_completed_IO(struct inode *inode)
 	struct ext4_inode_info *ei = EXT4_I(inode);
 	unsigned long flags;
 	int ret = 0;
-	int ret2 = 0;
 
 	dump_completed_IO(inode);
 	spin_lock_irqsave(&ei->i_completed_io_lock, flags);
@@ -105,12 +104,10 @@ int ext4_flush_completed_IO(struct inode *inode)
 		 */
 		spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
 		ret = ext4_end_io_nolock(io);
-		if (ret < 0)
-			ret2 = ret;
 		spin_lock_irqsave(&ei->i_completed_io_lock, flags);
 	}
 	spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
-	return (ret2 < 0) ? ret2 : 0;
Quoted 9 lines

fs/ext4/fsync.c int ext4_flush_completed_IO(struct inode *inode) · line 111

Quoted 2 lines
fs/ext4/fsync.c +1 -0
+	return (ret < 0) ? ret : 0;
 }

Please note that there is a while loop involved here. Which means, that ret2 is used to store the last negative value of ret. And due to the loop, ret can be over-written in the next loop iteration, which we can afford, because we have already stored what we need to save, in ret2. And this ret2 value is used to return appropriate value to the caller.

Actually, what I really meant was, removing ret2 as merely "unneeded" might not be the right thing to do because once you apply your patch, you end up altering the value returned by this function!

If the return value is indeed wrong in the current code, you should rather be saying that this is a bug fix, with appropriate justification IMO.

Thanks,
Srivatsa S. Bhat

#4 lore raw

2011/11/20 Srivatsa S. Bhat <[email protected]>:

Quoted 45 lines · Srivatsa S. Bhat
Quoted 34 lines · Namjae Jeon
Quoted 2 lines

ret2 is not needed in ext4_flush_completed_IO().

Not needed? I went through the code briefly, and I don't agree.

Quoted 28 lines

---
 fs/ext4/fsync.c |    5 +----

 1 files changed, 1 insertions(+), 4 deletions(-)
fs/ext4/fsync.c +0 -4
index 00a2cb7..40397ac 100644
@@ -81,7 +81,6 @@ int ext4_flush_completed_IO(struct inode *inode)
      struct ext4_inode_info *ei = EXT4_I(inode);
      unsigned long flags;
      int ret = 0;
-    int ret2 = 0;
 
      dump_completed_IO(inode);
      spin_lock_irqsave(&ei->i_completed_io_lock, flags);
@@ -105,12 +104,10 @@ int ext4_flush_completed_IO(struct inode *inode)
               */
              spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
              ret = ext4_end_io_nolock(io);
-            if (ret < 0)
-                    ret2 = ret;
              spin_lock_irqsave(&ei->i_completed_io_lock, flags);
      }
      spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
-    return (ret2 < 0) ? ret2 : 0;
Quoted 9 lines

fs/ext4/fsync.c int ext4_flush_completed_IO(struct inode *inode) · line 111

Quoted 2 lines
fs/ext4/fsync.c +1 -0
+    return (ret < 0) ? ret : 0;
  }

Please note that there is a while loop involved here. Which means, that ret2 is used to store the last negative value of ret. And due to the loop, ret can be over-written in the next loop iteration, which we can afford, because we have already stored what we need to save, in ret2. And this ret2 value is used to return appropriate value to the caller.

Quoted 7 lines

Actually, what I really meant was, removing ret2 as merely "unneeded" might not be the right thing to do because once you apply your patch, you end up altering the value returned by this function!

If the return value is indeed wrong in the current code, you should rather be saying that this is a bug fix, with appropriate justification IMO.

Thanks for your review. My thinking was reaching for to while loop(). I will remember your advice.
Thanks Srivatsa.

Quoted 4 lines

Thanks,
Srivatsa S. Bhat