[PATCH v2] erofs: avoid useless memory allocation

Noboru Asai asai at sijam.com
Fri Mar 3 21:32:41 AEDT 2023


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

Signed-off-by: Noboru Asai <asai at sijam.com>
---
 fs/erofs/xattr.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c
index 60729b1220b6..58069bf3ba25 100644
--- a/fs/erofs/xattr.c
+++ b/fs/erofs/xattr.c
@@ -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. */
-- 
2.39.2



More information about the Linux-erofs mailing list