From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-xfs@vger.kernel.org,
"Gustavo A . R . Silva" <gustavoars@kernel.org>
Subject: Re: [PATCH 7/7] xfs: Replace one-element arrays with flexible-array members
Date: Tue, 20 Apr 2021 10:15:53 -0700 [thread overview]
Message-ID: <20210420171553.GM3122264@magnolia> (raw)
In-Reply-To: <20210419082804.2076124-8-hch@lst.de>
On Mon, Apr 19, 2021 at 10:28:04AM +0200, Christoph Hellwig wrote:
> From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
>
> There is a regular need in the kernel to provide a way to declare having
> a dynamically sized set of trailing elements in a structure. Kernel code
> should always use “flexible array members”[1] for these cases. The older
> style of one-element or zero-length arrays should no longer be used[2].
>
> Refactor the code according to the use of flexible-array members in
> multiple structures, instead of one-element arrays. Also, make use of
> the new struct_size() helper to properly calculate the size of some
> structures that contain flexible-array members.
>
> [1] https://en.wikipedia.org/wiki/Flexible_array_member
> [2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> [hch: rebased on top of the previous cleanups]
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good to me besides the naming thing; with those resolved,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> fs/xfs/libxfs/xfs_log_format.h | 6 +++---
> fs/xfs/xfs_extfree_item.c | 9 +++------
> fs/xfs/xfs_extfree_item.h | 4 ++--
> fs/xfs/xfs_ondisk.h | 6 +++---
> 4 files changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h
> index 639035052b4f65..9b218c30659ad7 100644
> --- a/fs/xfs/libxfs/xfs_log_format.h
> +++ b/fs/xfs/libxfs/xfs_log_format.h
> @@ -559,7 +559,7 @@ struct xfs_efi_log_format {
> uint16_t efi_size; /* size of this item */
> uint32_t efi_nextents; /* # extents to free */
> uint64_t efi_id; /* efi identifier */
> - struct xfs_extent efi_extents[1]; /* array of extents to free */
> + struct xfs_extent efi_extents[]; /* array of extents to free */
> };
>
> /*
> @@ -577,7 +577,7 @@ struct xfs_efi_log_format_32 {
> uint16_t efi_size; /* size of this item */
> uint32_t efi_nextents; /* # extents to free */
> uint64_t efi_id; /* efi identifier */
> - struct xfs_extent_32 efi_extents[1]; /* array of extents to free */
> + struct xfs_extent_32 efi_extents[]; /* array of extents to free */
> } __attribute__((packed));
>
> /*
> @@ -590,7 +590,7 @@ struct xfs_efd_log_format {
> uint16_t efd_size; /* size of this item */
> uint32_t efd_nextents; /* # of extents freed */
> uint64_t efd_efi_id; /* id of corresponding efi */
> - struct xfs_extent efd_extents[1]; /* array of extents freed */
> + struct xfs_extent efd_extents[]; /* array of extents freed */
> };
>
> /*
> diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c
> index a2abdfd3d076bf..8bea9c9ecf2042 100644
> --- a/fs/xfs/xfs_extfree_item.c
> +++ b/fs/xfs/xfs_extfree_item.c
> @@ -73,8 +73,7 @@ static inline int
> xfs_efi_log_item_sizeof(
> struct xfs_efi_log_format *elf)
> {
> - return sizeof(*elf) +
> - (elf->efi_nextents - 1) * sizeof(struct xfs_extent);
> + return struct_size(elf, efi_extents, elf->efi_nextents);
> }
>
> STATIC void
> @@ -194,8 +193,7 @@ static inline int
> xfs_efd_log_item_sizeof(
> struct xfs_efd_log_format *elf)
> {
> - return sizeof(struct xfs_efd_log_format) +
> - (elf->efd_nextents - 1) * sizeof(struct xfs_extent);
> + return struct_size(elf, efd_extents, elf->efd_nextents);
> }
>
> STATIC void
> @@ -636,8 +634,7 @@ xfs_efi_copy_format_32(
> struct xfs_efi_log_format_32 *src = buf->i_addr;
> unsigned int i;
>
> - if (buf->i_len != sizeof(*src) +
> - (src->efi_nextents - 1) * sizeof(struct xfs_extent_32)) {
> + if (buf->i_len != struct_size(src, efi_extents, src->efi_nextents)) {
> XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
> return -EFSCORRUPTED;
> }
> diff --git a/fs/xfs/xfs_extfree_item.h b/fs/xfs/xfs_extfree_item.h
> index 3bb62ef525f2e0..a01ce86145bb64 100644
> --- a/fs/xfs/xfs_extfree_item.h
> +++ b/fs/xfs/xfs_extfree_item.h
> @@ -55,7 +55,7 @@ struct xfs_efi_log_item {
> static inline int xfs_efi_item_sizeof(unsigned int nextents)
> {
> return sizeof(struct xfs_efi_log_item) +
> - (nextents - 1) * sizeof(struct xfs_extent);
> + nextents * sizeof(struct xfs_extent);
> }
>
> /*
> @@ -73,7 +73,7 @@ struct xfs_efd_log_item {
> static inline int xfs_efd_item_sizeof(unsigned int nextents)
> {
> return sizeof(struct xfs_efd_log_item) +
> - (nextents - 1) * sizeof(struct xfs_extent);
> + nextents * sizeof(struct xfs_extent);
> }
>
> /*
> diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
> index 739476f7dffa21..fa4b590671bf58 100644
> --- a/fs/xfs/xfs_ondisk.h
> +++ b/fs/xfs/xfs_ondisk.h
> @@ -118,9 +118,9 @@ xfs_check_ondisk_structs(void)
> /* log structures */
> XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format, 88);
> XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat, 24);
> - XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format, 32);
> - XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format, 32);
> - XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32, 28);
> + XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format, 16);
> + XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format, 16);
> + XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32, 16);
> XFS_CHECK_STRUCT_SIZE(struct xfs_extent, 16);
> XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32, 12);
> XFS_CHECK_STRUCT_SIZE(struct xfs_log_dinode, 176);
> --
> 2.30.1
>
next prev parent reply other threads:[~2021-04-20 17:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 8:27 cleanup the EFI/EFD definitions Christoph Hellwig
2021-04-19 8:27 ` [PATCH 1/7] xfs: remove the EFD size asserts in xlog_recover_efd_commit_pass2 Christoph Hellwig
2021-04-20 16:26 ` Darrick J. Wong
2021-04-19 8:27 ` [PATCH 2/7] xfs: clean up the EFI and EFD log format handling Christoph Hellwig
2021-04-20 17:05 ` Darrick J. Wong
2021-04-21 5:55 ` Christoph Hellwig
2021-04-22 0:19 ` Darrick J. Wong
2021-04-19 8:28 ` [PATCH 3/7] xfs: pass a xfs_efi_log_item to xfs_efi_item_sizeof Christoph Hellwig
2021-04-20 17:09 ` Darrick J. Wong
2021-04-21 5:56 ` Christoph Hellwig
2021-04-22 0:29 ` Darrick J. Wong
2021-04-19 8:28 ` [PATCH 4/7] xfs: pass a xfs_efd_log_item to xfs_efd_item_sizeof Christoph Hellwig
2021-04-20 17:10 ` Darrick J. Wong
2021-04-19 8:28 ` [PATCH 5/7] xfs: add a xfs_efi_item_sizeof helper Christoph Hellwig
2021-04-20 17:11 ` Darrick J. Wong
2021-04-19 8:28 ` [PATCH 6/7] xfs: add a xfs_efd_item_sizeof helper Christoph Hellwig
2021-04-20 17:12 ` Darrick J. Wong
2021-04-19 8:28 ` [PATCH 7/7] xfs: Replace one-element arrays with flexible-array members Christoph Hellwig
2021-04-20 17:15 ` Darrick J. Wong [this message]
2021-04-20 22:16 ` Gustavo A. R. Silva
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=20210420171553.GM3122264@magnolia \
--to=djwong@kernel.org \
--cc=gustavoars@kernel.org \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.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