diff mbox series

[f2fs-dev] f2fs-tools: initialize allocated node area

Message ID 20231013222453.240961-1-daeho43@gmail.com (mailing list archive)
State New
Headers show
Series [f2fs-dev] f2fs-tools: initialize allocated node area | expand

Commit Message

Daeho Jeong Oct. 13, 2023, 10:24 p.m. UTC
From: Daeho Jeong <daehojeong@google.com>

Need to initialize allocated node areas after memory allocation.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 fsck/node.c       | 1 +
 include/f2fs_fs.h | 2 ++
 2 files changed, 3 insertions(+)

Comments

Chao Yu Oct. 16, 2023, 6:33 a.m. UTC | #1
On 2023/10/14 6:24, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> Need to initialize allocated node areas after memory allocation.
> 
> Signed-off-by: Daeho Jeong <daehojeong@google.com>
> ---
>   fsck/node.c       | 1 +
>   include/f2fs_fs.h | 2 ++
>   2 files changed, 3 insertions(+)
> 
> diff --git a/fsck/node.c b/fsck/node.c
> index 3761470..6508340 100644
> --- a/fsck/node.c
> +++ b/fsck/node.c
> @@ -127,6 +127,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
>   
>   	node_blk = calloc(BLOCK_SZ, 1);

calloc() has already initialized memory w/ zero, it doesn't need to reinitialize
it again?

>   	ASSERT(node_blk);
> +	memset(node_blk, 0, BLOCK_SZ);
>   
>   	F2FS_NODE_FOOTER(node_blk)->nid = cpu_to_le32(dn->nid);
>   	F2FS_NODE_FOOTER(node_blk)->ino = F2FS_NODE_FOOTER(f2fs_inode)->ino;
> diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> index 3c7451c..7e22278 100644
> --- a/include/f2fs_fs.h
> +++ b/include/f2fs_fs.h
> @@ -1826,6 +1826,8 @@ static inline void show_version(const char *prog)
>   static inline void f2fs_init_inode(struct f2fs_super_block *sb,
>   		struct f2fs_node *raw_node, nid_t ino, time_t mtime, mode_t mode)
>   {
> +	memset(raw_node, 0, F2FS_BLKSIZE);

Ditto,

Thanks,

> +
>   	F2FS_NODE_FOOTER(raw_node)->nid = cpu_to_le32(ino);
>   	F2FS_NODE_FOOTER(raw_node)->ino = cpu_to_le32(ino);
>   	F2FS_NODE_FOOTER(raw_node)->cp_ver = cpu_to_le64(1);
Daeho Jeong Oct. 16, 2023, 3:25 p.m. UTC | #2
On Sun, Oct 15, 2023 at 11:33 PM Chao Yu <chao@kernel.org> wrote:
>
> On 2023/10/14 6:24, Daeho Jeong wrote:
> > From: Daeho Jeong <daehojeong@google.com>
> >
> > Need to initialize allocated node areas after memory allocation.
> >
> > Signed-off-by: Daeho Jeong <daehojeong@google.com>
> > ---
> >   fsck/node.c       | 1 +
> >   include/f2fs_fs.h | 2 ++
> >   2 files changed, 3 insertions(+)
> >
> > diff --git a/fsck/node.c b/fsck/node.c
> > index 3761470..6508340 100644
> > --- a/fsck/node.c
> > +++ b/fsck/node.c
> > @@ -127,6 +127,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
> >
> >       node_blk = calloc(BLOCK_SZ, 1);
>
> calloc() has already initialized memory w/ zero, it doesn't need to reinitialize
> it again?

Sorry, I was confused. :(


>
> >       ASSERT(node_blk);
> > +     memset(node_blk, 0, BLOCK_SZ);
> >
> >       F2FS_NODE_FOOTER(node_blk)->nid = cpu_to_le32(dn->nid);
> >       F2FS_NODE_FOOTER(node_blk)->ino = F2FS_NODE_FOOTER(f2fs_inode)->ino;
> > diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> > index 3c7451c..7e22278 100644
> > --- a/include/f2fs_fs.h
> > +++ b/include/f2fs_fs.h
> > @@ -1826,6 +1826,8 @@ static inline void show_version(const char *prog)
> >   static inline void f2fs_init_inode(struct f2fs_super_block *sb,
> >               struct f2fs_node *raw_node, nid_t ino, time_t mtime, mode_t mode)
> >   {
> > +     memset(raw_node, 0, F2FS_BLKSIZE);
>
> Ditto,
>
> Thanks,
>
> > +
> >       F2FS_NODE_FOOTER(raw_node)->nid = cpu_to_le32(ino);
> >       F2FS_NODE_FOOTER(raw_node)->ino = cpu_to_le32(ino);
> >       F2FS_NODE_FOOTER(raw_node)->cp_ver = cpu_to_le64(1);
diff mbox series

Patch

diff --git a/fsck/node.c b/fsck/node.c
index 3761470..6508340 100644
--- a/fsck/node.c
+++ b/fsck/node.c
@@ -127,6 +127,7 @@  block_t new_node_block(struct f2fs_sb_info *sbi,
 
 	node_blk = calloc(BLOCK_SZ, 1);
 	ASSERT(node_blk);
+	memset(node_blk, 0, BLOCK_SZ);
 
 	F2FS_NODE_FOOTER(node_blk)->nid = cpu_to_le32(dn->nid);
 	F2FS_NODE_FOOTER(node_blk)->ino = F2FS_NODE_FOOTER(f2fs_inode)->ino;
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 3c7451c..7e22278 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1826,6 +1826,8 @@  static inline void show_version(const char *prog)
 static inline void f2fs_init_inode(struct f2fs_super_block *sb,
 		struct f2fs_node *raw_node, nid_t ino, time_t mtime, mode_t mode)
 {
+	memset(raw_node, 0, F2FS_BLKSIZE);
+
 	F2FS_NODE_FOOTER(raw_node)->nid = cpu_to_le32(ino);
 	F2FS_NODE_FOOTER(raw_node)->ino = cpu_to_le32(ino);
 	F2FS_NODE_FOOTER(raw_node)->cp_ver = cpu_to_le64(1);