public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Lezcano" <daniel.lezcano@oss.qualcomm.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v1 07/14] hwmon:: Use non-OF thermal cooling device register function
Date: Sun, 19 Apr 2026 18:47:46 +0000	[thread overview]
Message-ID: <20260419184747.2E84DC2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260419182203.4083985-8-daniel.lezcano@oss.qualcomm.com>

Sashiko AI review found 2 potential issue(s):
- [High] This problem wasn't introduced by this patch, but in mlxreg-fan.c, the hwmon sysfs interfaces are exposed before the thermal cooling device pointer (pwm->cdev) is initialized, leading to a possible NULL pointer dereference.
- [High] This problem wasn't introduced by this patch, but in mlxreg-fan.c, the variables pwm->last_hwmon_state and pwm->last_thermal_state are read and modified concurrently without any locking, leading to inconsistent hardware state.
--

commit c24a43d962cbf165d7c767a5a51aa1a15586bd28
Author: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>

hwmon:: Use non-OF thermal cooling device register function

Make HWMON drivers which are not based on device tree to use the
corresponding non-OF functions.

[ ... ]

> diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c
> index 137a90dd20752..860de6cfd8a4d 100644
> --- a/drivers/hwmon/mlxreg-fan.c
> +++ b/drivers/hwmon/mlxreg-fan.c
> @@ -583,8 +583,8 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan)
>  		pwm->fan = fan;
>  		/* Set minimal PWM speed. */
>  		pwm->last_hwmon_state = MLXREG_FAN_PWM_DUTY2STATE(MLXREG_FAN_MIN_DUTY);

This isn't a bug introduced by this commit, but are pwm->last_hwmon_state and
pwm->last_thermal_state read and modified concurrently without locking?

The function mlxreg_fan_write() (executed via sysfs) and
mlxreg_fan_set_cur_state() (executed by the thermal subsystem) concurrently
access and mutate these variables.

While the hwmon core serializes sysfs operations via
hwmon_device_register_with_info(), it does not serialize calls from the
thermal subsystem.

Because there is no lock protecting this multi-variable state, can a
Time-Of-Check to Time-Of-Use race occur? One thread may evaluate the maximum
of the two states using stale data and write an incorrectly low value to the
hardware.

Does this violate the hwmon subsystem guidelines requiring drivers to
implement locking for attributes registered by any other means?

> -		pwm->cdev = devm_thermal_of_cooling_device_register(dev, NULL, mlxreg_fan_name[i],
> -								    pwm, &mlxreg_fan_cooling_ops);
> +		pwm->cdev = devm_thermal_cooling_device_register(dev, mlxreg_fan_name[i],
> +								 pwm, &mlxreg_fan_cooling_ops);

This problem also wasn't introduced by this commit, but are the hwmon sysfs
interfaces exposed before the thermal cooling device pointer (pwm->cdev) is
initialized?

In mlxreg_fan_probe(), the hwmon device is registered via
devm_hwmon_device_register_with_info() before mlxreg_fan_cooling_config() is
called.  This exposes sysfs attributes to user-space immediately.

If a user writes to the PWM attribute in this narrow window, mlxreg_fan_write()
will be invoked and pass the currently uninitialized pwm->cdev to
_mlxreg_fan_set_cur_state().

Can this lead to a NULL pointer dereference when cdev->devdata is
unconditionally dereferenced?

>  		if (IS_ERR(pwm->cdev)) {
>  			dev_err(dev, "Failed to register cooling device\n");
>  			return PTR_ERR(pwm->cdev);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260419182203.4083985-1-daniel.lezcano@oss.qualcomm.com?part=7

  reply	other threads:[~2026-04-19 18:47 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 18:21 [PATCH v1 00/14] Support cooling device with ID in the OF Daniel Lezcano
2026-04-19 18:21 ` [PATCH v1 01/14] thermal/of: Move OF code where it belongs to Daniel Lezcano
2026-04-19 18:47   ` sashiko-bot
2026-04-19 18:21 ` [PATCH v1 02/14] thermal/driver/tegra/soctherm: Use devm_ variant when registering a cooling device Daniel Lezcano
2026-04-19 18:38   ` sashiko-bot
2026-04-19 18:21 ` [PATCH v1 03/14] thermal/core: Make thermal_cooling_device_init_complete() non static Daniel Lezcano
2026-04-19 18:43   ` sashiko-bot
2026-04-19 18:21 ` [PATCH v1 04/14] thermal/of: Move the node pointer assignation in the OF code file Daniel Lezcano
2026-04-19 18:21 ` [PATCH v1 05/14] thermal/core: Remove node pointer parameter parameter when registering a tz Daniel Lezcano
2026-04-19 18:41   ` sashiko-bot
2026-04-19 18:21 ` [PATCH v1 06/14] thermal/core: Register cooling device non-OF drivers Daniel Lezcano
2026-04-19 18:29   ` sashiko-bot
2026-04-19 18:21 ` [PATCH v1 07/14] hwmon:: Use non-OF thermal cooling device register function Daniel Lezcano
2026-04-19 18:47   ` sashiko-bot [this message]
2026-04-19 18:21 ` [PATCH v1 08/14] thermal/core: Move OF functions def in the CONFIG_OF section in thermal.h Daniel Lezcano
2026-04-19 18:21 ` [PATCH v1 09/14] thermal/core: Put of_node field cooling device structure under Kconfig option Daniel Lezcano
2026-04-19 18:21 ` [PATCH v1 10/14] thermal/of: Rename the devm_thermal_of_cooling_device_register() function Daniel Lezcano
2026-04-19 18:34   ` sashiko-bot
2026-04-19 18:21 ` [PATCH v1 11/14] thermal/of: Introduce cooling device of_index Daniel Lezcano
2026-04-19 18:21 ` [PATCH v1 12/14] thermal/of: Pass the of_index and add a function to register with an index Daniel Lezcano
2026-04-19 18:21 ` [PATCH v1 13/14] thermal/of: Process cooling device index in cooling-spec Daniel Lezcano
2026-04-19 18:51   ` sashiko-bot
2026-04-19 18:21 ` [PATCH v1 14/14] dt-bindings: thermal: cooling-devices: Update support for 3 cells cooling device Daniel Lezcano

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=20260419184747.2E84DC2BCAF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=daniel.lezcano@oss.qualcomm.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko@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