Commit 5224f790 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva
Browse files

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

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].

This code was transformed with the help of Coccinelle:
(next-20220214$ spatch --jobs $(getconf _NPROCESSORS_ONLN) --sp-file script.cocci --include-headers --dir . > output.patch)

@@
identifier S, member, array;
type T1, T2;
@@

struct S {
  ...
  T1 member;
  T2 array[
- 0
  ];
};

UAPI and wireless changes were intentionally excluded from this patch
and will be sent out separately.

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

Link: https://github.com/KSPP/linux/issues/78


Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
parent 26291c54
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ struct memdesc_struct {
	unsigned long chksum;
	unsigned long optional_pa;
	unsigned long numclusters;
	struct memclust_struct cluster[0];
	struct memclust_struct cluster[];
};

struct dsr_struct {
+1 −1
Original line number Diff line number Diff line
@@ -420,7 +420,7 @@ typedef struct sal_log_processor_info {
	 * The rest of this structure consists of variable-length arrays, which can't be
	 * expressed in C.
	 */
	sal_log_mod_error_info_t info[0];
	sal_log_mod_error_info_t info[];
	/*
	 * This is what the rest looked like if C supported variable-length arrays:
	 *
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ struct ccwgroup_device {
	unsigned int count;
	struct device	dev;
	struct work_struct ungroup_work;
	struct ccw_device *cdev[0];
	struct ccw_device *cdev[];
};

/**
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ struct chsc_pnso_area {
	struct chsc_header response;
	u32:32;
	struct chsc_pnso_naihdr naihdr;
	struct chsc_pnso_naid_l2 entries[0];
	struct chsc_pnso_naid_l2 entries[];
} __packed __aligned(PAGE_SIZE);

#endif /* _ASM_S390_CHSC_H */
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ struct aob {

struct aob_rq_header {
	struct scm_device *scmdev;
	char data[0];
	char data[];
};

struct scm_device {
Loading