Skip to contentSkip to conversation

scsi: fc: Replace one-element arrays with flexible-array members

PATCH Applied Gustavo A. R. Silva 2 participants 3 messages Feb 14, 2022 – Mar 2, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: fc: Replace one-element arrays with flexible-array members

Use flexible-array members in struct fc_fdmi_attr_entry and fs_fdmi_attrs instead of one-element arrays, and refactor the code accordingly.

Also, this helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy().

https://github.com/KSPP/linux/issues/79
https://github.com/ClangBuiltLinux/linux/issues/1590

---
Changes in v2:
- Revert changes for _port_ due to protocol definition conflict.

- Update subject line.
- Update changelog text.

 drivers/scsi/libfc/fc_encode.h | 2 +-
 include/scsi/fc/fc_ms.h        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/libfc/fc_encode.h +1 -1
index 74ae7fd15d8d..7dcac3b6baa7 100644
@@ -246,7 +246,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
 				   &entry->type);
 		put_unaligned_be16(len, &entry->len);
 		put_unaligned_be64(lport->wwnn,
-				   (__be64 *)&entry->value[0]);
+				   (__be64 *)&entry->value);
 
 		/* Manufacturer */
 		entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
include/scsi/fc/fc_ms.h +2 -2
index 00191695233a..56a5d2b5a624 100644
@@ -158,7 +158,7 @@ struct fc_fdmi_port_name {
 struct fc_fdmi_attr_entry {
 	__be16		type;
 	__be16		len;
-	__u8		value[1];
+	__u8		value[];
 } __attribute__((__packed__));
 
 /*
@@ -166,7 +166,7 @@ struct fc_fdmi_attr_entry {
  */
 struct fs_fdmi_attrs {
 	__be32				numattrs;
-	struct fc_fdmi_attr_entry	attr[1];
+	struct fc_fdmi_attr_entry	attr[];
 } __attribute__((__packed__));
 
 /*
Signature · 1 line
2.27.0
#1 lore raw

Gustavo,

Quoted 3 lines

Use flexible-array members in struct fc_fdmi_attr_entry and fs_fdmi_attrs instead of one-element arrays, and refactor the code accordingly.

Applied to 5.18/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 9 lines · Gustavo A. R. Silva

Use flexible-array members in struct fc_fdmi_attr_entry and fs_fdmi_attrs instead of one-element arrays, and refactor the code accordingly.

Also, this helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy().

[...]

Applied to 5.18/scsi-queue, thanks!

[1/1] scsi: fc: Replace one-element arrays with flexible-array members

      https://git.kernel.org/mkp/scsi/c/c5b483d5c1a2
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering