Skip to contentSkip to conversation

fs/ext4/xattr: check the return value of ext4_xattr_inode_dec_ref()

PATCH Superseded Li Zhong 2 participants 3 messages Sep 9, 2022 – Sep 17, 2022 ext4 file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Zhong

author
#0 lore raw

PATCH 1/1 fs/ext4/xattr: check the return value of ext4_xattr_inode_dec_ref()

Check the return value of ext4_xattr_inode_dec_ref(), which could return error code and need to be warned.

---
 fs/ext4/xattr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ext4/xattr.c +3 -1
index 533216e80fa2..76141ed12bc2 100644
@@ -1540,7 +1540,9 @@ static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode,
 
 	err = ext4_xattr_inode_write(handle, ea_inode, value, value_len);
 	if (err) {
-		ext4_xattr_inode_dec_ref(handle, ea_inode);
+		err = ext4_xattr_inode_dec_ref(handle, ea_inode);
+		if (err)
+			ext4_warning_inode(ea_inode, "cleanup dec ref error %d", err);
 		iput(ea_inode);
 		return err;
 	}
Signature · 1 line
2.25.1
reviewer
#1 lore raw
Quoted 13 lines · Li Zhong

Check the return value of ext4_xattr_inode_dec_ref(), which could return error code and need to be warned.

---
 fs/ext4/xattr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ext4/xattr.c +0 -0
index 533216e80fa2..76141ed12bc2 100644

fs/ext4/xattr.c static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode, · line 1543

Quoted 5 lines
fs/ext4/xattr.c +1 -1
@@ -1540,7 +1540,9 @@ static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode,
 
 	err = ext4_xattr_inode_write(handle, ea_inode, value, value_len);
 	if (err) {
-		ext4_xattr_inode_dec_ref(handle, ea_inode);
+		err = ext4_xattr_inode_dec_ref(handle, ea_inode);

Hey Li,

My only concern here is in case ext4_xattr_inode_dec_ref() fails, we overwrite the err value and the actual err from ext4_xattr_inode_write() is lost.

I feel the ext4_xattr_inode_write() error code would be more valuable for the calling function hence that is the one we should propogate. Maybe we can just print the warning without overwriting err?

Regards,
Ojaswin

Quoted 8 lines
fs/ext4/xattr.c +2 -0
+		if (err)
+			ext4_warning_inode(ea_inode, "cleanup dec ref error %d", err);
 		iput(ea_inode);
 		return err;
 	}
Signature · 1 line
2.25.1
author
#2 lore raw
Quoted 22 lines · Ojaswin Mujoo
Quoted 13 lines · Li Zhong

Check the return value of ext4_xattr_inode_dec_ref(), which could return error code and need to be warned.

---
 fs/ext4/xattr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ext4/xattr.c +0 -0
index 533216e80fa2..76141ed12bc2 100644

fs/ext4/xattr.c static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode, · line 1543

Quoted 5 lines
fs/ext4/xattr.c +1 -1
@@ -1540,7 +1540,9 @@ static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode,
 
      err = ext4_xattr_inode_write(handle, ea_inode, value, value_len);
      if (err) {
-             ext4_xattr_inode_dec_ref(handle, ea_inode);
+             err = ext4_xattr_inode_dec_ref(handle, ea_inode);

Hey Li,

Quoted 8 lines

My only concern here is in case ext4_xattr_inode_dec_ref() fails, we overwrite the err value and the actual err from ext4_xattr_inode_write() is lost.

I feel the ext4_xattr_inode_write() error code would be more valuable for the calling function hence that is the one we should propogate. Maybe we can just print the warning without overwriting err?

Thanks for pointing this out! I'll fix it in v2 patch.

Quoted 11 lines

Regards,
Ojaswin

Quoted 8 lines
fs/ext4/xattr.c +2 -1
+             if (err)
+                     ext4_warning_inode(ea_inode, "cleanup dec ref error %d", err);
              iput(ea_inode);
              return err;
      }
--

2.25.1