From: sashiko-bot@kernel.org
To: "Shirong Zhao" <shxzhaosr@163.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2] hwmon: (tmp513) avoid divide by zero from rounded-down current LSB
Date: Sat, 05 Dec 2026 01:57:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-250918@kernel.org> (raw)
In-Reply-To: <20261205014552.39-1-shxzhaosr@163.com>
> tmp51x_calibrate() computes the current LSB as
>
> curr_lsb_ua = DIV_ROUND_CLOSEST_ULL(max_curr_ma * MILLI, 32767);
>
> and then derives pwr_lsb_uw = 20 * curr_lsb_ua and
>
> div = DIV_ROUND_CLOSEST_ULL(curr_lsb_ua * shunt_uohms, MICRO);
>
> so the calibration register write is DIV_ROUND_CLOSEST(40960, div).
> curr_lsb_ua decreasing with a larger shunt means that for large shunt
> resistors DIV_ROUND_CLOSEST_ULL() rounds it to 0. Both div and
> pwr_lsb_uw then become 0: the calibration division traps, and a later
> write to power1_crit (tmp51x_set_value(), DIV_ROUND_CLOSEST(val,
> pwr_lsb_uw)) traps as well, because tmp51x_is_visible() only hides the
> attributes when shunt_uohms is exactly 0.
>
> curr_lsb_ua is a minimum resolution that only needs to be >= 1 uA; round
> it up with DIV_ROUND_UP_ULL() instead of to the nearest. This keeps
> curr_lsb_ua, pwr_lsb_uw and div >= 1 for the entire valid shunt range and
> lets large (but valid) shunts calibrate normally instead of being
> disabled.
>
> Fixes: 59dfa75e5d82 ("hwmon: Add driver for Texas Instruments TMP512/513 sensor chips.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205014552.39-1-shxzhaosr@163.com?part=1
next prev parent reply other threads:[~2026-12-05 1:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 1:24 [PATCH] hwmon: (tmp513) fix division by zero when calibrating a large shunt Shirong Zhao
2026-12-05 1:37 ` sashiko-bot
2026-12-05 1:45 ` [PATCH v2] hwmon: (tmp513) avoid divide by zero from rounded-down current LSB Shirong Zhao
2026-12-05 1:57 ` sashiko-bot [this message]
2026-12-05 4:29 ` Guenter Roeck
2026-12-05 4:37 ` [PATCH v3] " Shirong Zhao
2026-12-05 4:48 ` sashiko-bot
2026-12-05 16:28 ` 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=sashiko-outbox-250918@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shxzhaosr@163.com \
/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