Skip to contentSkip to conversation

ext4: Fix unnecessary hold lock when judge jinode in ext4_inode_attach_jinode

PATCH In review Ye Bin 1 participant 2 messages Aug 22, 2020 ext4 file system

lore
Share & tools
lore

Ye Bin

author
#0 lore raw

PATCH 1/1 ext4: Fix unnecessary hold lock when judge jinode in ext4_inode_attach_jinode

---
 fs/ext4/inode.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ext4/inode.c +3 -4
index 3a196d81f594..3504b4cec5b8 100644
@@ -4100,12 +4100,11 @@ int ext4_inode_attach_jinode(struct inode *inode)
 		return 0;
 
 	jinode = jbd2_alloc_inode(GFP_KERNEL);
+	if (!jinode)
+		return -ENOMEM;
+
 	spin_lock(&inode->i_lock);
 	if (!ei->jinode) {
-		if (!jinode) {
-			spin_unlock(&inode->i_lock);
-			return -ENOMEM;
-		}
 		ei->jinode = jinode;
 		jbd2_journal_init_jbd_inode(ei->jinode, inode);
 		jinode = NULL;
Signature · 1 line
2.25.4
author
#1 lore raw

Sorry, please ignore it.

Quoted 25 lines · Ye Bin
---
  fs/ext4/inode.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
fs/ext4/inode.c +3 -4
index 3a196d81f594..3504b4cec5b8 100644
@@ -4100,12 +4100,11 @@ int ext4_inode_attach_jinode(struct inode *inode)
  		return 0;
 
  	jinode = jbd2_alloc_inode(GFP_KERNEL);
+	if (!jinode)
+		return -ENOMEM;
+
  	spin_lock(&inode->i_lock);
  	if (!ei->jinode) {
-		if (!jinode) {
-			spin_unlock(&inode->i_lock);
-			return -ENOMEM;
-		}
  		ei->jinode = jinode;
  		jbd2_journal_init_jbd_inode(ei->jinode, inode);
  		jinode = NULL;