* [PATCH v2] hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i
@ 2026-06-11 1:59 Potin Lai
2026-06-11 2:10 ` sashiko-bot
2026-06-11 5:10 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Potin Lai @ 2026-06-11 1:59 UTC (permalink / raw)
To: Guenter Roeck, Patrick Williams
Cc: linux-hwmon, linux-kernel, Cosmo Chou, Mike Hsieh, Potin Lai,
Potin Lai
Swap the high setting and low setting coefficients in the lm25066_coeff
table for LM5064, LM5066, and LM5066i. The coefficients were previously
mapped incorrectly, resulting in inverted current and power scaling.
Additionally, dynamically assign the exponent (R) registers inside the
probe's LM25066_DEV_SETUP_CL check. This ensures that the proper
exponent is applied (e.g., for LM25056, high setting power exponent
is -4, but low setting power exponent is -3).
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
---
Changes in v2:
- based on comment in v1, only swap the coefficients setting for LM5064/5066/5066i
- Link to v1: https://patch.msgid.link/20260610-lm25066-driver-fix-v1-1-ff9b39961a2a@quantatw.com
---
drivers/hwmon/pmbus/lm25066.c | 54 ++++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index dd7275a67a0a..6e23ada64e2f 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -132,23 +132,23 @@ static const struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
.R = -2,
},
[PSC_CURRENT_IN] = {
- .m = 10742,
- .b = 1552,
+ .m = 5456,
+ .b = 2118,
.R = -2,
},
[PSC_CURRENT_IN_L] = {
- .m = 5456,
- .b = 2118,
+ .m = 10742,
+ .b = 1552,
.R = -2,
},
[PSC_POWER] = {
- .m = 1204,
- .b = 8524,
+ .m = 612,
+ .b = 11202,
.R = -3,
},
[PSC_POWER_L] = {
- .m = 612,
- .b = 11202,
+ .m = 1204,
+ .b = 8524,
.R = -3,
},
[PSC_TEMPERATURE] = {
@@ -167,23 +167,23 @@ static const struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
.R = -2,
},
[PSC_CURRENT_IN] = {
- .m = 10753,
- .b = -1200,
+ .m = 5405,
+ .b = -600,
.R = -2,
},
[PSC_CURRENT_IN_L] = {
- .m = 5405,
- .b = -600,
+ .m = 10753,
+ .b = -1200,
.R = -2,
},
[PSC_POWER] = {
- .m = 1204,
- .b = -6000,
+ .m = 605,
+ .b = -8000,
.R = -3,
},
[PSC_POWER_L] = {
- .m = 605,
- .b = -8000,
+ .m = 1204,
+ .b = -6000,
.R = -3,
},
[PSC_TEMPERATURE] = {
@@ -202,23 +202,23 @@ static const struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
.R = -2,
},
[PSC_CURRENT_IN] = {
- .m = 15076,
- .b = -504,
+ .m = 7645,
+ .b = 100,
.R = -2,
},
[PSC_CURRENT_IN_L] = {
- .m = 7645,
- .b = 100,
+ .m = 15076,
+ .b = -504,
.R = -2,
},
[PSC_POWER] = {
- .m = 1701,
- .b = -4000,
+ .m = 861,
+ .b = -965,
.R = -3,
},
[PSC_POWER_L] = {
- .m = 861,
- .b = -965,
+ .m = 1701,
+ .b = -4000,
.R = -3,
},
[PSC_TEMPERATURE] = {
@@ -519,18 +519,20 @@ static int lm25066_probe(struct i2c_client *client)
info->m[PSC_VOLTAGE_OUT] = coeff[PSC_VOLTAGE_OUT].m;
info->b[PSC_VOLTAGE_OUT] = coeff[PSC_VOLTAGE_OUT].b;
info->R[PSC_VOLTAGE_OUT] = coeff[PSC_VOLTAGE_OUT].R;
- info->R[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].R;
- info->R[PSC_POWER] = coeff[PSC_POWER].R;
if (config & LM25066_DEV_SETUP_CL) {
info->m[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN_L].m;
info->b[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN_L].b;
+ info->R[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN_L].R;
info->m[PSC_POWER] = coeff[PSC_POWER_L].m;
info->b[PSC_POWER] = coeff[PSC_POWER_L].b;
+ info->R[PSC_POWER] = coeff[PSC_POWER_L].R;
} else {
info->m[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].m;
info->b[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].b;
+ info->R[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].R;
info->m[PSC_POWER] = coeff[PSC_POWER].m;
info->b[PSC_POWER] = coeff[PSC_POWER].b;
+ info->R[PSC_POWER] = coeff[PSC_POWER].R;
}
/*
---
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
change-id: 20260610-lm25066-driver-fix-ae435577fce1
Best regards,
--
Potin Lai <potin.lai@quantatw.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i
2026-06-11 1:59 [PATCH v2] hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i Potin Lai
@ 2026-06-11 2:10 ` sashiko-bot
2026-06-11 5:10 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-06-11 2:10 UTC (permalink / raw)
To: Potin Lai; +Cc: linux-hwmon
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Multiplication of `info->m` with `shunt` can overflow a 32-bit unsigned integer, leading to drastically incorrect PMBus coefficients.
--
commit afaf15dfc17bb11eae6bb630c7de46aab3eda6b1
Author: Potin Lai <potin.lai.pt@gmail.com>
hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i
This commit swaps the high and low setting coefficients in the lm25066_coeff
table for the LM5064, LM5066, and LM5066i. It also dynamically assigns the
exponent (R) registers inside the LM25066_DEV_SETUP_CL check in the probe
function.
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
[ ... ]
> @@ -519,18 +519,20 @@ static int lm25066_probe(struct i2c_client *client)
> } else {
> info->m[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].m;
> info->b[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].b;
> + info->R[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].R;
> info->m[PSC_POWER] = coeff[PSC_POWER].m;
> info->b[PSC_POWER] = coeff[PSC_POWER].b;
> + info->R[PSC_POWER] = coeff[PSC_POWER].R;
> }
>
> /*
[Severity: High]
This is a pre-existing issue, but could this multiplication overflow a 32-bit
unsigned integer?
Looking at the lines immediately following this block in lm25066_probe():
info->m[PSC_CURRENT_IN] = info->m[PSC_CURRENT_IN] * shunt / 1000;
info->m[PSC_POWER] = info->m[PSC_POWER] * shunt / 1000;
The calculations evaluate the multiplication using 32-bit arithmetic because
info->m is an int and shunt is a u32. For large coefficients like 26882
(LM25056) or 15076 (LM5066i), a device tree shunt-resistor-micro-ohms value
exceeding roughly 159,000 causes the intermediate product to exceed UINT_MAX
(4,294,967,295), silently wrapping around before the division by 1000.
If the wrapped value has the most significant bit set, converting it back to
the signed int info->m results in negative coefficients. This leads to
incorrect current and power readings, which could cause erratic thermal or
power management behavior.
Should these calculations be cast to a 64-bit integer before multiplication to
avoid the overflow?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260611-lm25066-driver-fix-v2-1-5d28861b0d8e@quantatw.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i
2026-06-11 1:59 [PATCH v2] hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i Potin Lai
2026-06-11 2:10 ` sashiko-bot
@ 2026-06-11 5:10 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-06-11 5:10 UTC (permalink / raw)
To: Potin Lai
Cc: Patrick Williams, linux-hwmon, linux-kernel, Cosmo Chou,
Mike Hsieh, Potin Lai
On Thu, Jun 11, 2026 at 09:59:48AM +0800, Potin Lai wrote:
> Swap the high setting and low setting coefficients in the lm25066_coeff
> table for LM5064, LM5066, and LM5066i. The coefficients were previously
> mapped incorrectly, resulting in inverted current and power scaling.
>
> Additionally, dynamically assign the exponent (R) registers inside the
> probe's LM25066_DEV_SETUP_CL check. This ensures that the proper
> exponent is applied (e.g., for LM25056, high setting power exponent
> is -4, but low setting power exponent is -3).
>
> Signed-off-by: Potin Lai <potin.lai@quantatw.com>
When I tried to apply this patch, I got:
WARNING: From:/Signed-off-by: email address mismatch: 'From: Potin Lai <potin.lai.pt@gmail.com>' != 'Signed-off-by: Potin Lai <potin.lai@quantatw.com>'
You'll have to decide which e-mail address to use; it has to be consistent.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-11 5:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 1:59 [PATCH v2] hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i Potin Lai
2026-06-11 2:10 ` sashiko-bot
2026-06-11 5:10 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.