[PATCH] scsi: megaraid: Fix firmware version truncation
From: xujiahao
Date: Thu Nov 05 2026 - 22:48:53 EST
The HP firmware encoding writes "%c%d%d.%d%d" into adapter->fw_version
and adapter->bios_version, which are 7-byte buffers. The format can
produce 8 characters plus the terminator, so revisions with larger
field values would be truncated, and gcc reports it in a W=1 build:
drivers/scsi/megaraid.c:317:36: warning: '%d' directive output may be truncated writing between 1 and 2 bytes into a region of size between 1 and 2 [-Wformat-truncation=]
drivers/scsi/megaraid.c:324:36: warning: '%d' directive output may be truncated writing between 1 and 2 bytes into a region of size between 1 and 2 [-Wformat-truncation=]
Size both buffers to 16 bytes, the same size struct mega_adapinfo uses
for the same strings, and pass the size of the buffer being written
when formatting bios_version.
The non-HP path copies 4 bytes into the buffers and terminates them at
[4], and all consumers print them with %s or compare them with
strcmp(), so the larger buffers change nothing else.
Signed-off-by: xujiahao <xujiahao@xxxxxxxxxxxxxxxxxxxx>
---
drivers/scsi/megaraid.c | 2 +-
drivers/scsi/megaraid.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index a4079866f..a4995078f 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -320,7 +320,7 @@ mega_query_adapter(adapter_t *adapter)
adapter->product_info.fw_version[1] & 0x0f,
0,
adapter->product_info.fw_version[0] & 0x0f);
- snprintf(adapter->bios_version, sizeof(adapter->fw_version),
+ snprintf(adapter->bios_version, sizeof(adapter->bios_version),
"%c%d%d.%d%d",
adapter->product_info.bios_version[2],
0,
diff --git a/drivers/scsi/megaraid.h b/drivers/scsi/megaraid.h
index ecbaa0a0a..e95d99e83 100644
--- a/drivers/scsi/megaraid.h
+++ b/drivers/scsi/megaraid.h
@@ -830,8 +830,8 @@ typedef struct {
/* Host adapter parameters */
u8 numldrv;
- u8 fw_version[7];
- u8 bios_version[7];
+ u8 fw_version[16];
+ u8 bios_version[16];
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *controller_proc_dir_entry;
--
2.43.0