Skip to contentSkip to conversation

erofs: avoid useless memory allocation

PATCH New Noboru Asai 1 participant 1 message Mar 3, 2023 EROFS file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 erofs: avoid useless memory allocation

The variable 'vi->xattr_shared_count' could be ZERO.

---
 fs/erofs/xattr.c | 3 +++
 1 file changed, 3 insertions(+)
fs/erofs/xattr.c +3 -0
index 60729b1220b6..58069bf3ba25 100644
@@ -80,6 +80,8 @@ static int init_inode_xattrs(struct inode *inode)
 
 	ih = (struct erofs_xattr_ibody_header *)(it.kaddr + it.ofs);
 	vi->xattr_shared_count = ih->h_shared_count;
+	if (!vi->xattr_shared_count)
+		goto out_put_metabuf;
 	vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count,
 						sizeof(uint), GFP_KERNEL);
 	if (!vi->xattr_shared_xattrs) {
@@ -110,6 +112,7 @@ static int init_inode_xattrs(struct inode *inode)
 			le32_to_cpu(*(__le32 *)(it.kaddr + it.ofs));
 		it.ofs += sizeof(__le32);
 	}
+out_put_metabuf:
 	erofs_put_metabuf(&it.buf);
 
 	/* paired with smp_mb() at the beginning of the function. */
Signature · 1 line
2.39.2