From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Zhu Jun <zhujun2@cmss.chinamobile.com>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: temperature: mcp9600: Bound thresholds before scaling
Date: Tue, 10 Nov 2026 00:44:22 +0200 [thread overview]
Message-ID: <avJMxjqjpgDO-web@ashevche-desk.local> (raw)
In-Reply-To: <20261109093518.5418-1-zhujun2@cmss.chinamobile.com>
On Mon, Nov 09, 2026 at 05:35:17PM +0800, Zhu Jun wrote:
>
> mcp9600_write_thresh() multiplies the integer part by 1000000 before
> clamping to the supported temperature range. The multiplication can
> overflow int, so a request such as 3000 degrees can select the lower
> threshold instead of the upper threshold.
>
> Clamp the integer part to the hot-junction range before scaling. Keep
> the existing final clamp for fractional values and the narrower cold-
> junction range.
...
> + val = clamp_val(val, MCP9600_MIN_TEMP_HOT_JUNCTION_MICRO / 1000000,
> + MCP9600_MAX_TEMP_HOT_JUNCTION_MICRO / 1000000);
Use MICRO from units.h (but be careful about sign.
> /* Scale value to include decimal part into calculations */
> s_val = (val < 0) ? ((val * 1000000) - val2) :
> ((val * 1000000) + val2);
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-09 22:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 9:35 Zhu Jun
2026-11-09 10:04 ` Joshua Crofts
2026-11-09 22:44 ` Andy Shevchenko [this message]
2026-11-09 23:01 ` Joshua Crofts
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=avJMxjqjpgDO-web@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=zhujun2@cmss.chinamobile.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
all inboxes | Powered by JetHome®