Skip to contentSkip to conversation

bcachefs: Replace zero-length arrays with flexible-array members

PATCH In review Gustavo A. R. Silva 4 participants 4 messages Nov 28, 2023 – Nov 29, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: Replace zero-length arrays with flexible-array members

Fake flexible arrays (zero-length and one-element arrays) are deprecated, and should be replaced by flexible-array members.

So, replace zero-length arrays with flexible-array members in multiple structures.

---
 fs/bcachefs/bcachefs_ioctl.h | 4 ++--
 fs/bcachefs/io_read.c        | 2 +-
 fs/bcachefs/move.c           | 2 +-
 fs/bcachefs/replicas_types.h | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
fs/bcachefs/bcachefs_ioctl.h +2 -2
index 44ba7a87aea7..43822c17297c 100644
@@ -276,7 +276,7 @@ struct bch_ioctl_fs_usage {
 	__u32			replica_entries_bytes;
 	__u32			pad;
 
-	struct bch_replicas_usage replicas[0];
+	struct bch_replicas_usage replicas[];
 };
 
 /*
@@ -313,7 +313,7 @@ struct bch_ioctl_dev_usage_v2 {
 	__u32			bucket_size;
 	__u64			nr_buckets;
 
-	struct bch_ioctl_dev_usage_type  d[0];
+	struct bch_ioctl_dev_usage_type d[];
 };
 
 /*
fs/bcachefs/io_read.c +1 -1
index 3281c4dd1d52..4c9eaf7cea8d 100644
@@ -80,7 +80,7 @@ struct promote_op {
 	struct bpos		pos;
 
 	struct data_update	write;
-	struct bio_vec		bi_inline_vecs[0]; /* must be last */
+	struct bio_vec		bi_inline_vecs[]; /* must be last */
 };
 
 static const struct rhashtable_params bch_promote_params = {
fs/bcachefs/move.c +1 -1
index c5518a866276..5a693c3e2ed2 100644
@@ -81,7 +81,7 @@ struct moving_io {
 
 	struct data_update		write;
 	/* Must be last since it is variable size */
-	struct bio_vec			bi_inline_vecs[0];
+	struct bio_vec			bi_inline_vecs[];
 };
 
 static void move_free(struct moving_io *io)
fs/bcachefs/replicas_types.h +1 -1
index 030324078bba..ac90d142c4e8 100644
@@ -21,7 +21,7 @@ struct replicas_delta_list {
 	u64			nr_inodes;
 	u64			persistent_reserved[BCH_REPLICAS_MAX];
 	struct			{} memset_end;
-	struct replicas_delta	d[0];
+	struct replicas_delta	d[];
 };
 
 #endif /* _BCACHEFS_REPLICAS_TYPES_H */
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Gustavo A. R. Silva

Fake flexible arrays (zero-length and one-element arrays) are deprecated, and should be replaced by flexible-array members.

So, replace zero-length arrays with flexible-array members in multiple structures.

These look like straight-forward conversions. Thanks!

Signature · 1 line
Kees Cook
#2 lore raw
Quoted 10 lines · Kees Cook
Quoted 7 lines · Gustavo A. R. Silva

Fake flexible arrays (zero-length and one-element arrays) are deprecated, and should be replaced by flexible-array members.

So, replace zero-length arrays with flexible-array members in multiple structures.

These look like straight-forward conversions. Thanks!

Yep, these also fix a buch of -Warray-bounds warnings reported by 0-day:

https://lore.kernel.org/lkml/[email protected]/

Quoted 3 lines

Thanks!
--
Gustavo

#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 7 lines · Gustavo A. R. Silva

Fake flexible arrays (zero-length and one-element arrays) are deprecated, and should be replaced by flexible-array members.

So, replace zero-length arrays with flexible-array members in multiple structures.

There are some ZLAs I hadn't converted because they led to new warnings
- in particular, array of flexible members.

I don't think that applies to any of the ones you changed (replicas_delta_list, maybe?) - but it's something we need to figure out if we're getting serious about this.