scst: 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:
($ 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
  ];
};

[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
This commit is contained in:
Gleb Chesnokov
2022-04-03 14:44:17 +03:00
parent 87b687ac0f
commit a1ded333e8
10 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ struct buf_segment {
struct __qelem entry;
unsigned int len;
char data[0];
char data[];
};
struct PDU {
+1 -1
View File
@@ -32,7 +32,7 @@ struct isns_hdr {
uint16_t flags;
uint16_t transaction;
uint16_t sequence;
uint32_t pdu[0];
uint32_t pdu[];
} __attribute__ ((packed));
struct isns_tlv {
+2 -2
View File
@@ -157,7 +157,7 @@ struct qla84_msg_mgmt {
uint16_t rsrvd;
struct qla84_mgmt_param mgmtp;/* parameters for cmd */
uint32_t len; /* bytes in payload following this struct */
uint8_t payload[0]; /* payload for cmd */
uint8_t payload[]; /* payload for cmd */
};
struct qla_bsg_a84_mgmt {
@@ -216,7 +216,7 @@ struct qla_image_version {
struct qla_image_version_list {
uint32_t count;
struct qla_image_version version[0];
struct qla_image_version version[];
} __packed;
struct qla_status_reg {
+1 -1
View File
@@ -5456,7 +5456,7 @@ struct ql_vnd_stat_entry {
struct ql_vnd_stats {
u64 entry_count; /* Num of entries */
u64 rservd;
struct ql_vnd_stat_entry entry[0]; /* Place holder of entries */
struct ql_vnd_stat_entry entry[]; /* Place holder of entries */
} __packed;
struct ql_vnd_host_stats_resp {
+2 -2
View File
@@ -121,7 +121,7 @@ struct app_pinfo {
struct app_pinfo_reply {
uint8_t port_count;
uint8_t reserved[VND_CMD_APP_RESERVED_SIZE];
struct app_pinfo ports[0];
struct app_pinfo ports[];
} __packed;
struct app_sinfo_req {
@@ -140,7 +140,7 @@ struct app_sinfo {
struct app_stats_reply {
uint8_t elem_count;
struct app_sinfo elem[0];
struct app_sinfo elem[];
} __packed;
struct qla_sa_update_frame {
+1 -1
View File
@@ -1716,7 +1716,7 @@ struct qla_flt_header {
__le16 length;
__le16 checksum;
__le16 unused;
struct qla_flt_region region[0];
struct qla_flt_region region[];
};
#define FLT_REGION_SIZE 16
+1 -1
View File
@@ -121,7 +121,7 @@ struct qla84_msg_mgmt {
uint16_t rsrvd;
struct qla84_mgmt_param mgmtp;/* parameters for cmd */
uint32_t len; /* bytes in payload following this struct */
uint8_t payload[0]; /* payload for cmd */
uint8_t payload[]; /* payload for cmd */
};
struct qla_bsg_a84_mgmt {
+1 -1
View File
@@ -149,7 +149,7 @@ struct scst_event_stpg_payload {
aligned_u64 stpg_cmd_tag;
uint8_t device_name[64];
uint16_t stpg_descriptors_cnt;
struct scst_event_stpg_descr stpg_descriptors[0];
struct scst_event_stpg_descr stpg_descriptors[];
};
#define SCST_EVENT_REG_VIRT_DEV 6
+1 -1
View File
@@ -354,7 +354,7 @@ struct scst_user_get_multi {
int16_t replies_done; /* out */
int16_t cmds_cnt; /* in/out */
int16_t pad;
struct scst_user_get_cmd cmds[0]; /* out */
struct scst_user_get_cmd cmds[]; /* out */
};
#define SCST_USER_REGISTER_DEVICE _IOW('u', 1, struct scst_user_dev_desc)
+1 -1
View File
@@ -50,7 +50,7 @@ struct sgv_pool_obj {
void *allocator_priv;
struct trans_tbl_ent *trans_tbl;
struct scatterlist *sg_entries;
struct scatterlist sg_entries_data[0];
struct scatterlist sg_entries_data[];
};
/*