Skip to contentSkip to conversation

scsi: mpt3sas: Fix a possible divide-by-zero bug in base_mod64()

PATCH New Tuo Li 1 participant 1 message Aug 11, 2021

Subsystems (2)
lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 scsi: mpt3sas: Fix a possible divide-by-zero bug in base_mod64()

The variable divisor is checked in:
if (!divisor)

This indicates that divisor can be NULL.
If so, a divide-by-zero bug will occur:
remainder = do_div(dividend, divisor);

To fix the possible bug, the function returns 0 when divisor is zero.

---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/mpt3sas/mpt3sas_base.c +3 -1
index 19b1c0cf5f2a..3550998ea38b 100644
@@ -1594,8 +1594,10 @@ static u32 base_mod64(u64 dividend, u32 divisor)
 {
 	u32 remainder;
 
-	if (!divisor)
+	if (!divisor) {
 		pr_err("mpt3sas: DIVISOR is zero, in div fn\n");
+		return 0;
+	}
 	remainder = do_div(dividend, divisor);
 	return remainder;
 }
Signature · 1 line
2.25.1