Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 2/2] hwmon: (cros_ec) Handle temperature conversion overflows
Date: Tue, 30 Jun 2026 21:10:27 +0000	[thread overview]
Message-ID: <20260630211028.69BA21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630-cros_ec-hwmon-overflow-v1-2-3d2ecd3eb0f2@weissschuh.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Using `BUILD_BUG()` with runtime variables introduces build fragility because it relies on compiler Value Range Propagation (VRP) to eliminate the branch.
--

commit a22cd7f1036247302ddc232e1cbd36ceb641e202
Author: Thomas Weißschuh <linux@weissschuh.net>

hwmon: (cros_ec) Handle temperature conversion overflows

The calculations converting between the different temperature units can
overflow, resulting in incorrect data. Detect these overflows and report them.

> diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
> index 44291799dd8e4..4b402142b46f3 100644
> --- a/drivers/hwmon/cros_ec_hwmon.c
> +++ b/drivers/hwmon/cros_ec_hwmon.c

[ ... ]

> @@ -150,14 +152,28 @@ static bool cros_ec_hwmon_is_error_temp(u8 temp)
>  /* This differs slightly from the variant in units.h to avoid rounding inconsistencies. */
>  #define CROS_EC_HWMON_ABSOLUTE_ZERO_MILLICELSIUS (-273000)

[ ... ]

> -static long cros_ec_hwmon_temp_to_millicelsius(u8 temp)
> +static long __flatten cros_ec_hwmon_temp_to_millicelsius(u8 temp)
>  {
> -	return cros_ec_hwmon_kelvin_to_millicelsius((((long)temp) + EC_TEMP_SENSOR_OFFSET));
> +	long ret;
> +
> +	if (check_add_overflow(temp, EC_TEMP_SENSOR_OFFSET, &ret))
> +		BUILD_BUG();

[Severity: Low]
Does the use of BUILD_BUG() with the runtime variable temp risk spurious build
failures?

Relying on the compiler's Value Range Propagation (VRP) to eliminate the
check_add_overflow() branch can lead to broken builds when compiling with
CONFIG_CC_OPTIMIZE_FOR_DEBUGGING (which uses -Og) or on older toolchains where
VRP fails to eliminate the branch.

> +
> +	if (cros_ec_hwmon_kelvin_to_millicelsius_overflow(ret, &ret))
> +		BUILD_BUG();
> +
> +	return ret;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260630-cros_ec-hwmon-overflow-v1-0-3d2ecd3eb0f2@weissschuh.net?part=2

  reply	other threads:[~2026-06-30 21:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 20:57 [PATCH 0/2] hwmon: (cros_ec) Rework the temperature conversions Thomas Weißschuh
2026-06-30 20:57 ` [PATCH 1/2] hwmon: (cros_ec) Implement custom kelvin to celsius conversions Thomas Weißschuh
2026-06-30 21:11   ` sashiko-bot
2026-06-30 23:07   ` Guenter Roeck
2026-06-30 20:57 ` [PATCH 2/2] hwmon: (cros_ec) Handle temperature conversion overflows Thomas Weißschuh
2026-06-30 21:10   ` sashiko-bot [this message]
2026-06-30 21:21     ` Thomas Weißschuh
2026-06-30 23:06   ` 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=20260630211028.69BA21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox