From: Greg KH <gregkh@linuxfoundation.org>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Jan Kara <jack@suse.cz>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ext4: Use struct_size() to improve ext4_htree_store_dirent()
Date: Tue, 5 Nov 2024 11:39:13 +0100 [thread overview]
Message-ID: <2024110539-frugality-glutton-58f0@gregkh> (raw)
In-Reply-To: <20241105103353.11590-2-thorsten.blum@linux.dev>
On Tue, Nov 05, 2024 at 11:33:54AM +0100, Thorsten Blum wrote:
> Inline and use struct_size() to calculate the number of bytes to
> allocate for new_fn and remove the local variable len.
>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> This change was originally part of another patch that was split into two
> separate patches after feedback from Greg KH
> - Link: https://lore.kernel.org/r/20241104234214.8094-2-thorsten.blum@linux.dev/
> ---
> fs/ext4/dir.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> index 233479647f1b..02d47a64e8d1 100644
> --- a/fs/ext4/dir.c
> +++ b/fs/ext4/dir.c
> @@ -471,14 +471,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
> struct rb_node **p, *parent = NULL;
> struct fname *fname, *new_fn;
> struct dir_private_info *info;
> - int len;
>
> info = dir_file->private_data;
> p = &info->root.rb_node;
>
> /* Create and allocate the fname structure */
> - len = sizeof(struct fname) + ent_name->len + 1;
> - new_fn = kzalloc(len, GFP_KERNEL);
> + new_fn = kzalloc(struct_size(new_fn, name, ent_name->len + 1),
> + GFP_KERNEL);
Does this actually matter and make the code any more robust or faster?
The original code here is easier to read and understand, why add
complexity if it is not required?
thanks,
greg k-h
next prev parent reply other threads:[~2024-11-05 10:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 10:33 [PATCH] ext4: Use struct_size() to improve ext4_htree_store_dirent() Thorsten Blum
2024-11-05 10:39 ` Greg KH [this message]
2024-11-05 11:06 ` Thorsten Blum
2024-11-05 12:11 ` Greg KH
2024-11-14 13:53 ` Theodore Ts'o
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=2024110539-frugality-glutton-58f0@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thorsten.blum@linux.dev \
--cc=tytso@mit.edu \
/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