OCFS2-Devel Archive mirror
 help / color / mirror / Atom feed
From: Joseph Qi <jiangqi903@gmail.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
	akpm <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	ocfs2-devel@lists.linux.dev,
	Joseph Qi <joseph.qi@linux.alibaba.com>
Subject: Re: [PATCH 2/2] ocfs2: Use struct_size()
Date: Mon, 17 Jul 2023 10:16:23 +0800	[thread overview]
Message-ID: <00b0a06a-b220-9176-5046-cd6068bf22fd@gmail.com> (raw)
In-Reply-To: <9d99ea2090739f816d0dc0c4ebaa42b26fc48a9e.1689533270.git.christophe.jaillet@wanadoo.fr>



On 7/17/23 2:48 AM, Christophe JAILLET wrote:
> Use struct_size() instead of hand-writing it, when allocating a structure
> with a flex array.
> 
> This is less verbose.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Looks fine.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
> It will also be helpful if the __counted_by() annotation is added with a
> Coccinelle script such as:
>    https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=devel/counted_by&id=adc5b3cb48a049563dc673f348eab7b6beba8a9b
> ---
>  fs/ocfs2/journal.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
> index 2f7e70109020..4e779efe2a4e 100644
> --- a/fs/ocfs2/journal.c
> +++ b/fs/ocfs2/journal.c
> @@ -114,9 +114,9 @@ int ocfs2_compute_replay_slots(struct ocfs2_super *osb)
>  	if (osb->replay_map)
>  		return 0;
>  
> -	replay_map = kzalloc(sizeof(struct ocfs2_replay_map) +
> -			     (osb->max_slots * sizeof(char)), GFP_KERNEL);
> -
> +	replay_map = kzalloc(struct_size(replay_map, rm_replay_slots,
> +					 osb->max_slots),
> +			     GFP_KERNEL);
>  	if (!replay_map) {
>  		mlog_errno(-ENOMEM);
>  		return -ENOMEM;

  reply	other threads:[~2023-07-17  2:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-16 18:48 [PATCH 1/2] ocfs2: Use flexible array in 'struct ocfs2_recovery_map' Christophe JAILLET
2023-07-16 18:48 ` [PATCH 2/2] ocfs2: Use struct_size() Christophe JAILLET
2023-07-17  2:16   ` Joseph Qi [this message]
2023-07-17  2:15 ` [PATCH 1/2] ocfs2: Use flexible array in 'struct ocfs2_recovery_map' Joseph Qi

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=00b0a06a-b220-9176-5046-cd6068bf22fd@gmail.com \
    --to=jiangqi903@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=ocfs2-devel@lists.linux.dev \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).