lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <wxh5qw7hzvvyg4texozjbviicfe2xmbjxngwlc3a7xef6jm6kn@wi3f25t2fftd>
Date: Tue, 29 Apr 2025 21:40:38 -0400
From: Kent Overstreet <kent.overstreet@...ux.dev>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: linux-bcachefs@...r.kernel.org, linux-kernel@...r.kernel.org, 
	linux-hardening@...r.kernel.org
Subject: Re: [PATCH][next] bcachefs: Avoid -Wflex-array-member-not-at-end
 warning

On Tue, Apr 29, 2025 at 07:15:37PM -0600, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
> 
> Use the `DEFINE_FLEX()` helper for on-stack definitions of a flexible
> structure where the size of the flexible-array member is known at
> compile-time, and refactor the rest of the code, accordingly.
> 
> So, with these changes, fix the following warning:
> 
> fs/bcachefs/disk_accounting.c:429:51: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

We also have bch_replicas_padded, does that also need a fix?

And, DEFINE_FLEX() is gross, can we try to stop reinventing language
syntax with macros?

Could we not have done this with an __attribute__(())?

Or just swap the anonymous struct for a union, since that's apparently
what DEFINE_FLEX() does?

> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
> ---
>  fs/bcachefs/disk_accounting.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c
> index 7be71952425c..381e666679d2 100644
> --- a/fs/bcachefs/disk_accounting.c
> +++ b/fs/bcachefs/disk_accounting.c
> @@ -425,24 +425,22 @@ int bch2_fs_replicas_usage_read(struct bch_fs *c, darray_char *usage)
>  
>  	percpu_down_read(&c->mark_lock);
>  	darray_for_each(acc->k, i) {
> -		struct {
> -			struct bch_replicas_usage r;
> -			u8 pad[BCH_BKEY_PTRS_MAX];
> -		} u;
> +		DEFINE_FLEX(struct bch_replicas_usage, u, r.devs, r.nr_devs,
> +			    BCH_BKEY_PTRS_MAX);
>  
> -		if (!accounting_to_replicas(&u.r.r, i->pos))
> +		if (!accounting_to_replicas(&u->r, i->pos))
>  			continue;
>  
>  		u64 sectors;
>  		bch2_accounting_mem_read_counters(acc, i - acc->k.data, &sectors, 1, false);
> -		u.r.sectors = sectors;
> +		u->sectors = sectors;
>  
> -		ret = darray_make_room(usage, replicas_usage_bytes(&u.r));
> +		ret = darray_make_room(usage, replicas_usage_bytes(u));
>  		if (ret)
>  			break;
>  
> -		memcpy(&darray_top(*usage), &u.r, replicas_usage_bytes(&u.r));
> -		usage->nr += replicas_usage_bytes(&u.r);
> +		memcpy(&darray_top(*usage), u, replicas_usage_bytes(u));
> +		usage->nr += replicas_usage_bytes(u);
>  	}
>  	percpu_up_read(&c->mark_lock);
>  
> -- 
> 2.43.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ