diff mbox series

scsi: qla2xxx: fix fortify warning

Message ID 20240111141145.122306-1-dmantipov@yandex.ru (mailing list archive)
State Deferred
Headers show
Series scsi: qla2xxx: fix fortify warning | expand

Commit Message

Dmitry Antipov Jan. 11, 2024, 2:11 p.m. UTC
When compiling with gcc version 14.0.0 20240108 (experimental) and
CONFIG_FORTIFY_SOURCE=y, I've noticed the following warning:

In function 'fortify_memcpy_chk',
    inlined from 'qla81xx_nvram_config' at drivers/scsi/qla2xxx/qla_init.c:9190:2:
./include/linux/fortify-string.h:588:25: warning: call to '__read_overflow2_field'
declared with attribute warning: detected read beyond size of field (2nd parameter);
maybe use struct_group()? [-Wattribute-warning]
  588 |                         __read_overflow2_field(q_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This call to 'memcpy()' is interpreted as an attempt to copy
'sizeof(struct ex_init_cb_81xx)' bytes from 2-byte 'ex_version'
field of 'struct nvram_81xx' and thus overread warning is issued.
Since we actually want to copy the whole control block in 81xx
format, use the convenient 'struct_group' for the latter.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/scsi/qla2xxx/qla_fw.h   | 18 ++++++++++--------
 drivers/scsi/qla2xxx/qla_init.c |  2 +-
 2 files changed, 11 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/qla2xxx/qla_fw.h b/drivers/scsi/qla2xxx/qla_fw.h
index f307beed9d29..9d5031827082 100644
--- a/drivers/scsi/qla2xxx/qla_fw.h
+++ b/drivers/scsi/qla2xxx/qla_fw.h
@@ -1942,14 +1942,16 @@  struct nvram_81xx {
 	__le16	reserved_6[24];
 
 	/* Offset 128. */
-	__le16	ex_version;
-	uint8_t prio_fcf_matching_flags;
-	uint8_t reserved_6_1[3];
-	__le16	pri_fcf_vlan_id;
-	uint8_t pri_fcf_fabric_name[8];
-	__le16	reserved_6_2[7];
-	uint8_t spma_mac_addr[6];
-	__le16	reserved_6_3[14];
+	struct_group(ex_cb_81xx,
+		__le16	ex_version;
+		uint8_t prio_fcf_matching_flags;
+		uint8_t reserved_6_1[3];
+		__le16	pri_fcf_vlan_id;
+		uint8_t pri_fcf_fabric_name[8];
+		__le16	reserved_6_2[7];
+		uint8_t spma_mac_addr[6];
+		__le16	reserved_6_3[14];
+	);
 
 	/* Offset 192. */
 	uint8_t min_supported_speed;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a314cfc5b263..c20acdd634ea 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -9187,7 +9187,7 @@  qla81xx_nvram_config(scsi_qla_host_t *vha)
 	}
 
 	/* Use extended-initialization control block. */
-	memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
+	memcpy(ha->ex_init_cb, &nv->ex_cb_81xx, sizeof(*ha->ex_init_cb));
 	ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
 	/*
 	 * Setup driver NVRAM options.