diff mbox series

[1/2] scsi: message: fusion: fix array index check in mpt_sas_log_info()

Message ID 20231128171352.221822-1-aleksei.kodanev@bell-sw.com
State New
Headers show
Series [1/2] scsi: message: fusion: fix array index check in mpt_sas_log_info() | expand

Commit Message

Alexey Kodanev Nov. 28, 2023, 5:13 p.m. UTC
"sas_loginfo.dw.originator" index for "originator_str" array currently
has an obscure check that looks like a typo because it does the opposite,
exiting the function if index is in the valid range. But if "bus_type"
not equals "SAS" and index is invalid, it will proceed to get the string,
even though it should exit anyway in the switch below.

Detected using the static analysis tool - Svace.

Fixes: 466544d8898f ("[SCSI] fusion SAS support (mptsas driver) updates")
Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
---
 drivers/message/fusion/mptbase.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 4bf669c55649..4f507fc2f02d 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -8076,8 +8076,8 @@  mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info, u8 cb_idx)
 	char *sub_code_desc = NULL;
 
 	sas_loginfo.loginfo = log_info;
-	if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
-	    (sas_loginfo.dw.originator < ARRAY_SIZE(originator_str)))
+	if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) ||
+	    (sas_loginfo.dw.originator >= ARRAY_SIZE(originator_str)))
 		return;
 
 	originator_desc = originator_str[sas_loginfo.dw.originator];