[PATCH 1/2] erofs-utils: allocate `struct erofs_inode` with zeroed memory
Gao Xiang
hsiangkao at linux.alibaba.com
Sun Apr 6 00:39:36 AEDT 2025
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 at linux.alibaba.com>
---
fsck/main.c | 5 +----
fuse/main.c | 6 +++---
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/fsck/main.c b/fsck/main.c
index 0e8b944..f7e33c0 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -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)
diff --git a/fuse/main.c b/fuse/main.c
index cb2759e..db4f323 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -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;
--
2.43.5
More information about the Linux-erofs
mailing list