diff mbox series

ext4: Call ext4_journal_stop(handle) only once in ext4_dio_write_iter()

Message ID cf895072-43cf-412c-bced-8268498ad13e@web.de
State New
Headers show
Series ext4: Call ext4_journal_stop(handle) only once in ext4_dio_write_iter() | expand

Commit Message

Markus Elfring Sept. 25, 2024, 7:54 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 25 Sep 2024 21:47:39 +0200

An ext4_journal_stop(handle) call was immediately used after a return value
check for a ext4_orphan_add() call in this function implementation.
Thus call such a function only once instead directly before the check.

This issue was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/ext4/file.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

--
2.46.1

Comments

Zhang Yi Sept. 26, 2024, 3:45 a.m. UTC | #1
On 2024/9/26 3:54, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 25 Sep 2024 21:47:39 +0200
> 
> An ext4_journal_stop(handle) call was immediately used after a return value
> check for a ext4_orphan_add() call in this function implementation.
> Thus call such a function only once instead directly before the check.
> 
> This issue was transformed by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

> ---
>  fs/ext4/file.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index f14aed14b9cf..23005f1345a8 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -564,12 +564,9 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
>  		}
> 
>  		ret = ext4_orphan_add(handle, inode);
> -		if (ret) {
> -			ext4_journal_stop(handle);
> -			goto out;
> -		}
> -
>  		ext4_journal_stop(handle);
> +		if (ret)
> +			goto out;
>  	}
> 
>  	if (ilock_shared && !unwritten)
> --
> 2.46.1
> 
>
Jan Kara Sept. 26, 2024, 7:55 a.m. UTC | #2
On Wed 25-09-24 21:54:18, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 25 Sep 2024 21:47:39 +0200
> 
> An ext4_journal_stop(handle) call was immediately used after a return value
> check for a ext4_orphan_add() call in this function implementation.
> Thus call such a function only once instead directly before the check.
> 
> This issue was transformed by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/file.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index f14aed14b9cf..23005f1345a8 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -564,12 +564,9 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
>  		}
> 
>  		ret = ext4_orphan_add(handle, inode);
> -		if (ret) {
> -			ext4_journal_stop(handle);
> -			goto out;
> -		}
> -
>  		ext4_journal_stop(handle);
> +		if (ret)
> +			goto out;
>  	}
> 
>  	if (ilock_shared && !unwritten)
> --
> 2.46.1
>
diff mbox series

Patch

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index f14aed14b9cf..23005f1345a8 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -564,12 +564,9 @@  static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 		}

 		ret = ext4_orphan_add(handle, inode);
-		if (ret) {
-			ext4_journal_stop(handle);
-			goto out;
-		}
-
 		ext4_journal_stop(handle);
+		if (ret)
+			goto out;
 	}

 	if (ilock_shared && !unwritten)