diff mbox series

[v3,1/3] jffs2: avoid unnecessarily taking f->sem

Message ID 61e099b717000558fec733995211813d1b34b56d.1545126261.git.helmut.grohne@intenta.de
State New, archived
Delegated to: Richard Weinberger
Headers show
Series [v3,1/3] jffs2: avoid unnecessarily taking f->sem | expand

Commit Message

Helmut Grohne Dec. 18, 2018, 9:52 a.m. UTC
jffs2_xattr_do_crccheck_inode creates a temporary struct
jffs2_inode_info for handling it to jffs2_do_read_inode_internal.
Formerly, jffs2_do_read_inode_internal released f->sem in the error path
and that was why it had to be initialized, taken and released. As part
of 7aaea7605c0 ("jffs2: fix unbalanced locking") locking was moved out
of it.

In the relevant jffs2_xattr_do_crccheck_inode we own the only reference
to f as we allocate it with kmalloc. Since nothing else has knowledge of
it, there is no need to lock it. In particular, that saves us from
thinking about the correct locking class.

We still need to initialize the mutex as jffs2_do_clear_inode insists on
acquiring it.

Signed-off-by: Helmut Grohne <helmut.grohne@intenta.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: Richard Weinberger <richard@nod.at>
---
 fs/jffs2/readinode.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 389ea53ea487..a6718fbfe1fd 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -1382,12 +1382,10 @@  int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *i
 	if (!f)
 		return -ENOMEM;
 
-	mutex_init(&f->sem);
-	mutex_lock(&f->sem);
 	f->inocache = ic;
 
 	ret = jffs2_do_read_inode_internal(c, f, &n);
-	mutex_unlock(&f->sem);
+	mutex_init(&f->sem);
 	jffs2_do_clear_inode(c, f);
 	jffs2_xattr_do_crccheck_inode(c, ic);
 	kfree (f);