All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Potin Lai" <potin.lai.pt@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2] hwmon: (pmbus/lm25066) Fix PMBus coefficients for LM5064/5066/5066i
Date: Thu, 11 Jun 2026 02:10:05 +0000	[thread overview]
Message-ID: <20260611021006.37D341F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260611-lm25066-driver-fix-v2-1-5d28861b0d8e@quantatw.com>

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

  reply	other threads:[~2026-06-11  2:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-06-11  5:10 ` Guenter Roeck

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=20260611021006.37D341F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=potin.lai.pt@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.