jffs2: fix potential deadlock in jffs2_do_setattr

Message ID 1507769765-13478-1-git-send-email-liu.song11@zte.com.cn
State New
Delegated to: David Woodhouse
Headers show
Series
  • jffs2: fix potential deadlock in jffs2_do_setattr
Related show

Commit Message

Liu Song Oct. 12, 2017, 12:56 a.m.
In jffs2_do_setattr, we hold two mutexes which are 
A) c->alloc_sem 
B) f->sem 
If new_metadata is error, then we release mutexes in bad sequence 
which could cause ABAB deadlock. 
This patch adjusts release sequence which could avoid deadlock. 

Signed-off-by: Liu Song <liu.song11@zte.com.cn>
Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>
---
 fs/jffs2/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch

diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 76fa814..f998126 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -140,9 +140,9 @@  int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
 		kfree(mdata);
 
 	if (IS_ERR(new_metadata)) {
-		jffs2_complete_reservation(c);
 		jffs2_free_raw_inode(ri);
 		mutex_unlock(&f->sem);
+		jffs2_complete_reservation(c);
 		return PTR_ERR(new_metadata);
 	}
 	/* It worked. Update the inode */