From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>,
clm@fb.com, dsterba@suse.com
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH] btrfs: Refactor allocation size calculation in kzalloc()
Date: Tue, 30 Sep 2025 18:49:55 +0930 [thread overview]
Message-ID: <76fa5e79-c7e8-4637-bf51-c0e6f4e04f51@gmx.com> (raw)
In-Reply-To: <20250930091440.25078-1-mehdi.benhadjkhelifa@gmail.com>
在 2025/9/30 18:44, Mehdi Ben Hadj Khelifa 写道:
> Wrap allocation size calculation in size_add() and size_mul() to avoid
> any potential overflow.
>
> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
> ---
> fs/btrfs/volumes.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index c6e3efd6f602..3f1f19b28aac 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -6076,12 +6076,11 @@ struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info,
> {
> struct btrfs_io_context *bioc;
>
> - bioc = kzalloc(
> - /* The size of btrfs_io_context */
> - sizeof(struct btrfs_io_context) +
> - /* Plus the variable array for the stripes */
> - sizeof(struct btrfs_io_stripe) * (total_stripes),
> - GFP_NOFS);
> + /* The size of btrfs_io_context */
> + /* Plus the variable array for the stripes */
> + bioc = kzalloc(size_add(sizeof(struct btrfs_io_context),
Please use struct_size() instead.
And if you're using struct_size() there iwll be no need for any comments.
> + size_mul(sizeof(struct btrfs_io_stripe),
> + total_stripes)), GFP_NOFS);
>
> if (!bioc)
> return NULL;
next prev parent reply other threads:[~2025-09-30 9:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 9:14 [PATCH] btrfs: Refactor allocation size calculation in kzalloc() Mehdi Ben Hadj Khelifa
2025-09-30 9:19 ` Qu Wenruo [this message]
2025-09-30 9:27 ` Mehdi Ben Hadj Khelifa
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=76fa5e79-c7e8-4637-bf51-c0e6f4e04f51@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=clm@fb.com \
--cc=david.hunter.linux@gmail.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mehdi.benhadjkhelifa@gmail.com \
--cc=skhan@linuxfoundation.org \
/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