erofs-utils: allocate `struct erofs_inode` with zeroed memory
authorGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 5 Apr 2025 13:39:36 +0000 (21:39 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 5 Apr 2025 16:25:21 +0000 (00:25 +0800)
The kernel implementation has the same constraint, so the code can
be shared.

Fixes: 9fd2a2250fa9 ("erofs-utils: fuse: switch to FUSE 2/3 lowlevel APIs")
Fixes: f44043561491 ("erofs-utils: introduce fsck.erofs")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20250405133937.2665477-1-hsiangkao@linux.alibaba.com
fsck/main.c
fuse/main.c

index 0e8b94417cda0cb81eeb156cd955c095b669f646..f7e33c053f883efad0ead89c345c372c0c77f732 100644 (file)
@@ -974,12 +974,9 @@ verify:
 static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)
 {
        int ret, i;
-       struct erofs_inode inode;
+       struct erofs_inode inode = {.sbi = &g_sbi, .nid = nid};
 
        erofs_dbg("check inode: nid(%llu)", nid | 0ULL);
-
-       inode.nid = nid;
-       inode.sbi = &g_sbi;
        ret = erofs_read_inode_from_disk(&inode);
        if (ret) {
                if (ret == -EIO)
index cb2759eb6bd1062e6842e70c63e4015605edea2c..db4f3236d9e8a0e5133a69e9c56c21f1570c89e4 100644 (file)
@@ -231,7 +231,7 @@ static void erofsfuse_open(fuse_req_t req, fuse_ino_t ino,
                return;
        }
 
-       vi = (struct erofs_inode *)malloc(sizeof(struct erofs_inode));
+       vi = calloc(1, sizeof(struct erofs_inode));
        if (!vi) {
                fuse_reply_err(req, ENOMEM);
                return;
@@ -281,7 +281,7 @@ static void erofsfuse_opendir(fuse_req_t req, fuse_ino_t ino,
        int ret;
        struct erofs_inode *vi;
 
-       vi = (struct erofs_inode *)malloc(sizeof(struct erofs_inode));
+       vi = calloc(1, sizeof(struct erofs_inode));
        if (!vi) {
                fuse_reply_err(req, ENOMEM);
                return;
@@ -324,7 +324,7 @@ static void erofsfuse_lookup(fuse_req_t req, fuse_ino_t parent,
        struct fuse_entry_param fentry = { 0 };
        struct erofsfuse_lookupdir_context ctx = { 0 };
 
-       vi = (struct erofs_inode *)malloc(sizeof(struct erofs_inode));
+       vi = calloc(1, sizeof(struct erofs_inode));
        if (!vi) {
                fuse_reply_err(req, ENOMEM);
                return;