Web lists-archives.com

[PATCH] jffs2: fix potential deadlock in jffs2_do_setattr




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@xxxxxxxxxx>
Reviewed-by: Jiang Biao <jiang.biao2@xxxxxxxxxx>
---
 fs/jffs2/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 */
-- 
2.1.0.GIT