From: "Pradhan, Sanman" <sanman.pradhan@hpe.com>
To: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>
Cc: "linux@roeck-us.net" <linux@roeck-us.net>,
"wenswang@yeah.net" <wenswang@yeah.net>,
"chou.cosmo@gmail.com" <chou.cosmo@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Sanman Pradhan <psanman@juniper.net>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH v2 5/5] hwmon: (pmbus/mp29502) Prevent division by zero from hardware register
Date: Mon, 23 Mar 2026 23:34:22 +0000 [thread overview]
Message-ID: <20260323233244.201294-6-sanman.pradhan@hpe.com> (raw)
In-Reply-To: <20260323233244.201294-1-sanman.pradhan@hpe.com>
From: Sanman Pradhan <psanman@juniper.net>
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@vger.kernel.org
Signed-off-by: Sanman Pradhan <psanman@juniper.net>
---
v2:
- No changes to this patch in this version.
---
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
prev parent reply other threads:[~2026-03-23 23:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260323233244.201294-1-sanman.pradhan@hpe.com>
2026-03-23 23:33 ` [PATCH v2 1/5] hwmon: (pmbus) Use -ENODATA for unhandled registers in MPS drivers Pradhan, Sanman
2026-03-23 23:33 ` [PATCH v2 2/5] hwmon: (pmbus) Fix return type truncation in MPS reg2data_linear11() Pradhan, Sanman
2026-03-23 23:33 ` [PATCH v2 3/5] hwmon: (pmbus/mp9945) Replace raw I2C calls with PMBus core API Pradhan, Sanman
2026-03-23 23:34 ` [PATCH v2 4/5] hwmon: (pmbus/mp29502) " Pradhan, Sanman
2026-03-23 23:34 ` Pradhan, Sanman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323233244.201294-6-sanman.pradhan@hpe.com \
--to=sanman.pradhan@hpe.com \
--cc=chou.cosmo@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=psanman@juniper.net \
--cc=stable@vger.kernel.org \
--cc=wenswang@yeah.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox