[PATCH 5/5] hwmon: (pmbus/mp29502) Prevent division by zero from hardware register
From: Pradhan, Sanman
Date: Mon Mar 23 2026 - 14:03:45 EST
From: Sanman Pradhan <psanman@xxxxxxxxxxx>
mp29502_identify_vout_divider() and mp29502_identify_ovp_divider() read
divider values from hardware registers (MFR_VOUT_PROT1 bits [11:0] and
MFR_SLOPE_CNT_SET bits [9:0]) into data->vout_bottom_div and
data->ovp_div respectively. These divisors are used in
DIV_ROUND_CLOSEST() calculations across multiple read and write paths:
vout_bottom_div feeds the PMBUS_READ_VOUT, PMBUS_READ_POUT, and
PMBUS_VOUT_UV_FAULT_LIMIT handlers in addition to the OV-limit helpers,
while ovp_div is used in mp29502_read_vout_ov_limit() and
mp29502_write_vout_ov_limit(). If the hardware returns zero for either
field, a division-by-zero exception occurs at runtime.
Add zero-value guards that return -EINVAL when a divisor is zero,
indicating the hardware returned an invalid configuration. This causes
probe to fail gracefully rather than crashing with a divide exception.
Fixes: 90bad684e9ac ("hwmon: add MP29502 driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Sanman Pradhan <psanman@xxxxxxxxxxx>
---
drivers/hwmon/pmbus/mp29502.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/hwmon/pmbus/mp29502.c b/drivers/hwmon/pmbus/mp29502.c
index aef9d957bdf1..bbcf018e5d05 100644
--- a/drivers/hwmon/pmbus/mp29502.c
+++ b/drivers/hwmon/pmbus/mp29502.c
@@ -134,6 +134,8 @@ mp29502_identify_vout_divider(struct i2c_client *client, struct pmbus_driver_inf
return ret;
data->vout_bottom_div = FIELD_GET(GENMASK(11, 0), ret);
+ if (!data->vout_bottom_div)
+ return -EINVAL;
ret = i2c_smbus_read_word_data(client, MFR_VOUT_PROT2);
if (ret < 0)
@@ -160,6 +162,8 @@ mp29502_identify_ovp_divider(struct i2c_client *client, struct pmbus_driver_info
return ret;
data->ovp_div = FIELD_GET(GENMASK(9, 0), ret);
+ if (!data->ovp_div)
+ return -EINVAL;
return 0;
}
--
2.34.1