linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: fix missing unlock on error in collapse range
@ 2014-05-27  0:09 Namjae Jeon
  2014-05-27 16:48 ` Theodore Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Namjae Jeon @ 2014-05-27  0:09 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: 'Dan Carpenter', linux-ext4, Ashish Sangwan

Add i_write_mutex unlock on the error handling path in collapse_range().

Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Ashish Sangwan <a.sangwan@samsung.com>
---
 fs/ext4/extents.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index ee14768..0c93423 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5447,8 +5447,10 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
 	/* Write out all dirty pages */
 	ret = filemap_write_and_wait_range(inode->i_mapping, ioffset,
 					   LLONG_MAX);
-	if (ret)
+	if (ret) {
+		mutex_unlock(&EXT4_I(inode)->i_write_mutex);
 		return ret;
+	}
 
 	/* Take mutex lock */
 	mutex_lock(&inode->i_mutex);
-- 
1.7.11-rc0


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

* Re: [PATCH] ext4: fix missing unlock on error in collapse range
  2014-05-27  0:09 [PATCH] ext4: fix missing unlock on error in collapse range Namjae Jeon
@ 2014-05-27 16:48 ` Theodore Ts'o
  2014-05-28  0:15   ` Namjae Jeon
  0 siblings, 1 reply; 3+ messages in thread
From: Theodore Ts'o @ 2014-05-27 16:48 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: 'Dan Carpenter', linux-ext4, Ashish Sangwan

On Tue, May 27, 2014 at 09:09:15AM +0900, Namjae Jeon wrote:
> Add i_write_mutex unlock on the error handling path in collapse_range().
> 
> Cc: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
> Signed-off-by: Ashish Sangwan <a.sangwan@samsung.com>
> ---
>  fs/ext4/extents.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Thanks for the patch!

This is the increment diff which I'm going to apply instead.  It
results in a net decrease of one line of code, instead of a net
increase of two, and it is more consistent in terms of the error
handling style.

Cheers,

					- Ted

 fs/ext4/extents.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 8ffab40..cb23a34 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5423,10 +5423,8 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
 	/* Call ext4_force_commit to flush all data in case of data=journal. */
 	if (ext4_should_journal_data(inode)) {
 		ret = ext4_force_commit(inode->i_sb);
-		if (ret) {
-			mutex_unlock(&EXT4_I(inode)->i_write_mutex);
-			return ret;
-		}
+		if (ret)
+			goto out_i_write_mutex;
 	}
 
 	/*
@@ -5439,7 +5437,7 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
 	ret = filemap_write_and_wait_range(inode->i_mapping, ioffset,
 					   LLONG_MAX);
 	if (ret)
-		return ret;
+		goto out_i_write_mutex;
 
 	/* Take mutex lock */
 	mutex_lock(&inode->i_mutex);
@@ -5512,6 +5510,7 @@ out_dio:
 	ext4_inode_resume_unlocked_dio(inode);
 out_mutex:
 	mutex_unlock(&inode->i_mutex);
+out_i_write_mutex:
 	mutex_unlock(&EXT4_I(inode)->i_write_mutex);
 	return ret;
 }

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

* RE: [PATCH] ext4: fix missing unlock on error in collapse range
  2014-05-27 16:48 ` Theodore Ts'o
@ 2014-05-28  0:15   ` Namjae Jeon
  0 siblings, 0 replies; 3+ messages in thread
From: Namjae Jeon @ 2014-05-28  0:15 UTC (permalink / raw)
  To: 'Theodore Ts'o'
  Cc: 'Dan Carpenter', 'linux-ext4',
	'Ashish Sangwan'

> 
> On Tue, May 27, 2014 at 09:09:15AM +0900, Namjae Jeon wrote:
> > Add i_write_mutex unlock on the error handling path in collapse_range().
> >
> > Cc: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
> > Signed-off-by: Ashish Sangwan <a.sangwan@samsung.com>
> > ---
> >  fs/ext4/extents.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> Thanks for the patch!
> 
> This is the increment diff which I'm going to apply instead.  It
> results in a net decrease of one line of code, instead of a net
> increase of two, and it is more consistent in terms of the error
> handling style.
Yes, Right. Thanks Ted!
> 
> Cheers,
> 
> 					- Ted
> 
>  fs/ext4/extents.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 8ffab40..cb23a34 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -5423,10 +5423,8 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
>  	/* Call ext4_force_commit to flush all data in case of data=journal. */
>  	if (ext4_should_journal_data(inode)) {
>  		ret = ext4_force_commit(inode->i_sb);
> -		if (ret) {
> -			mutex_unlock(&EXT4_I(inode)->i_write_mutex);
> -			return ret;
> -		}
> +		if (ret)
> +			goto out_i_write_mutex;
>  	}
> 
>  	/*
> @@ -5439,7 +5437,7 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
>  	ret = filemap_write_and_wait_range(inode->i_mapping, ioffset,
>  					   LLONG_MAX);
>  	if (ret)
> -		return ret;
> +		goto out_i_write_mutex;
> 
>  	/* Take mutex lock */
>  	mutex_lock(&inode->i_mutex);
> @@ -5512,6 +5510,7 @@ out_dio:
>  	ext4_inode_resume_unlocked_dio(inode);
>  out_mutex:
>  	mutex_unlock(&inode->i_mutex);
> +out_i_write_mutex:
>  	mutex_unlock(&EXT4_I(inode)->i_write_mutex);
>  	return ret;
>  }


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

end of thread, other threads:[~2014-05-28  0:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-27  0:09 [PATCH] ext4: fix missing unlock on error in collapse range Namjae Jeon
2014-05-27 16:48 ` Theodore Ts'o
2014-05-28  0:15   ` Namjae Jeon

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).