[PATCH] jffs2: fix potential deadlock in jffs2_do_setattr

Liu Song liu.song11 at zte.com.cn
Wed Oct 11 17:56:05 PDT 2017


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 at zte.com.cn>
Reviewed-by: Jiang Biao <jiang.biao2 at zte.com.cn>
---
 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




More information about the linux-mtd mailing list