Re: [PATCH 06/15] btrfs: move static_assert() for btrfs_super_block into fs.c

David Sterba
2022-09-19T20:59:48Z

On Wed, Sep 14, 2022 at 07:04:42PM -0400, Josef Bacik wrote:
> We shouldn't have static_assert()'s in header files in general,

Why? Since we have the _Static_assert support in all compilers we can do
the header compile-time checks.

> but
> especially since btrfs_super_block isn't defined in ctree.h.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
> fs/btrfs/ctree.h | 1 -
> fs/btrfs/fs.c | 2 ++
> 2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index a790c58b4c73..3cb4e0aca058 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -56,7 +56,6 @@ struct btrfs_ioctl_encoded_io_args;
>
> #define BTRFS_SUPER_INFO_OFFSET SZ_64K
> #define BTRFS_SUPER_INFO_SIZE 4096
> -static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
>
> +
> +static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);

This can be dropped as the same assert is right after the super block
definition and this is IMO the intended usage pattern. This catches any
accidental changes to the structure.