From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 2/2] fs: jffs2: zero initialize allocated inode
Date: Tue, 19 May 2026 14:59:38 +0200 [thread overview]
Message-ID: <8ba6cfa0-dce3-4617-b4ac-37d5db14c57f@pengutronix.de> (raw)
In-Reply-To: <20260519124448.3635366-2-s.hauer@pengutronix.de>
Hello Sascha,
On 5/19/26 2:44 PM, Sascha Hauer wrote:
> JFFS2 uses kmem_cache_alloc() to allocate an ubifs_inode. The memory
> returned from kmem_cache_alloc() is not zeroed. jffs2_alloc_inode()
> zeroes all fields in the ubifs_inode except the embedded struct inode.
> In Linux this is done in the kmem_cache constructor function which calls
> inode_init_once(). In barebox we have the constructor function as well,
> but we don't have an equivalent of inode_init_once(), so the constructor
> is empty. zero the inode in the constructor instead so that barebox
> gets a zeroed inode.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> fs/jffs2/super.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
> index b9a5b99744..260a812b7c 100644
> --- a/fs/jffs2/super.c
> +++ b/fs/jffs2/super.c
> @@ -55,8 +55,9 @@ static void jffs2_destroy_inode(struct inode *inode)
> kmem_cache_free(jffs2_inode_cachep, f);
> }
>
> -static void jffs2_i_init_once(void *foo)
> +static void jffs2_i_init_once(void *obj)
> {
> + memset(obj, 0, sizeof(struct inode));
jffs2_i_init_once is used as constructor for creating objects of
sizeof(struct jffs2_inode_info).
struct jffs2_inode_info has a struct inode member, but as the last
element, not the first, so this does nothing to initialize the inode by
the looks of it?
I'd rather suggest we zero the whole sizeof(jffs2_inode_info) here to be
on the safe side, even with respect to future updates.
Cheers,
Ahmad
> }
>
> static const struct super_operations jffs2_super_operations =
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-05-19 13:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 12:44 [PATCH 1/2] fs: ubifs: " Sascha Hauer
2026-05-19 12:44 ` [PATCH 2/2] fs: jffs2: " Sascha Hauer
2026-05-19 12:59 ` Ahmad Fatoum [this message]
2026-05-19 13:03 ` [PATCH 1/2] fs: ubifs: " Ahmad Fatoum
2026-05-19 13:14 ` Sascha Hauer
2026-05-19 13:16 ` Ahmad Fatoum
2026-05-19 13:28 Sascha Hauer
2026-05-19 13:28 ` [PATCH 2/2] fs: jffs2: " Sascha Hauer
2026-05-19 13:35 ` Ahmad Fatoum
2026-05-19 15:15 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8ba6cfa0-dce3-4617-b4ac-37d5db14c57f@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox