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 1/2] hwmon: (cros_ec) Implement custom kelvin to celsius conversions
Date: Tue, 30 Jun 2026 21:11:19 +0000	[thread overview]
Message-ID: <20260630211120.063A81F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260630-cros_ec-hwmon-overflow-v1-1-3d2ecd3eb0f2@weissschuh.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing hwmon core serialization in thermal cooling device callbacks, causing potential race conditions.
--

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

hwmon: (cros_ec) Implement custom kelvin to celsius conversions

The ChromeOS EC APIs use integers representing degrees kelvin for
temperatures. This commit implements a custom conversion which
preserves round values.

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

[ ... ]

> @@ -228,7 +236,7 @@ static int cros_ec_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
>  								cros_ec_hwmon_attr_to_thres(attr),
>  								&threshold);
>  			if (ret == 0)
> -				*val = kelvin_to_millicelsius(threshold);
> +				*val = cros_ec_hwmon_kelvin_to_millicelsius(threshold);
>  		}
>  	}
>  

While reviewing this driver, I noticed the following in the same file:

> static int cros_ec_hwmon_cooling_set_cur_state(struct thermal_cooling_device *cdev,
> 					       unsigned long val)
> {
> 	const struct cros_ec_hwmon_cooling_priv *priv = cdev->devdata;
> 
> 	return cros_ec_hwmon_write_pwm_input(priv->hwmon_priv->cros_ec, priv->index, val);
> }

[Severity: High]
This is a pre-existing issue, but does this cooling device callback need to
take the hwmon lock to prevent race conditions?

The thermal subsystem calls cros_ec_hwmon_cooling_set_cur_state()
asynchronously, which bypasses the hwmon core serialization.

Looking at cros_ec_hwmon_write_pwm_input(), it performs a read-modify-write
sequence on the EC PWM state:

cros_ec_hwmon_write_pwm_input()
    cros_ec_hwmon_read_pwm_enable(cros_ec, index, &control_method);
    if (control_method != 1) 
        return -EOPNOTSUPP;
    cros_ec_hwmon_set_fan_pwm_val(cros_ec, index, val);

Can this race with a concurrent sysfs write modifying the fan PWM, leading
to an incorrect fan control state? 

The hardware monitoring subsystem guidelines require drivers to use
hwmon_lock() and hwmon_unlock() for attributes registered outside the core
info parameter, such as these thermal cooling state callbacks.

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

  reply	other threads:[~2026-06-30 21:11 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 [this message]
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
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=20260630211120.063A81F00A3A@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