Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shih-Yuan Lee" <fourdollars@debian.org>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v5 3/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info
Date: Sat, 11 Jul 2026 08:12:37 +0000	[thread overview]
Message-ID: <20260711081237.A8A121F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260711075754.11358-4-fourdollars@debian.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The new `pwmX_enable` attribute implementation violates the standard hwmon ABI by mapping automatic mode to `0` and explicitly rejecting `2`.
--

--- Patch [3]: [PATCH v5 3/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info ---
commit 5c6fadffca7be1d46d146ede611dc2b9077f542a
Author: Shih-Yuan Lee <fourdollars@debian.org>

hwmon: (applesmc) Convert to hwmon_device_register_with_info

This commit converts the legacy hwmon_device_register() function in the
applesmc driver to the modern hwmon_device_register_with_info() API. It
dynamically allocates standard hwmon channels and standardizes attribute
naming, such as mapping the legacy fanX_manual attributes to the standard
pwmX_enable ABI.

> diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
> index 317135fc4b73b..bec9e9e988969 100644
> --- a/drivers/hwmon/applesmc.c
> +++ b/drivers/hwmon/applesmc.c

[ ... ]

> @@ -1321,8 +1186,238 @@ static const struct dmi_system_id applesmc_whitelist[] __initconst = {
> +static int applesmc_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
> +			       u32 attr, int channel, long *val)
> +{
> +	int ret;
> +
> +	switch (type) {

[ ... ]

> +	case hwmon_pwm:
> +		if (attr == hwmon_pwm_enable) {
> +			u8 buffer[2];
> +
> +			ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
> +			if (ret)
> +				return ret;
> +			*val = ((buffer[0] << 8 | buffer[1]) >> channel) & 0x01;

[Severity: High]
Does returning 0 when the fan is in automatic control mode conflict with the
standard hwmon ABI?

The standard hwmon ABI defines 2 as automatic control, while 0 typically
means 'no control' or 'full speed'. Returning 0 here might cause standard
userspace tools like fancontrol or pwmconfig from lm-sensors to incorrectly
assume the fan has no speed control.

> +			return 0;
> +		}
> +		break;
> +	default:
> +		break;
> +	}
> +	return -EOPNOTSUPP;
> +}
> +
> +static int applesmc_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
> +				u32 attr, int channel, long val)
> +{
> +	int ret;
> +
> +	switch (type) {

[ ... ]

> +	case hwmon_pwm:
> +		if (attr == hwmon_pwm_enable) {
> +			u8 buffer[2];
> +			u16 manual_val;
> +			const struct applesmc_entry *entry;
> +
> +			if (val != 0 && val != 1)
> +				return -EINVAL;

[Severity: High]
Will rejecting standard hwmon ABI values like 2 break userspace tools?

By explicitly returning -EINVAL for values other than 0 or 1, attempts to
restore automatic mode by writing 2 (the standard hwmon ABI value for
automatic control) will fail. This could leave the fan stuck in manual mode
at an arbitrary speed, risking system overheating.

Since this patch standardizes the attribute name to pwmX_enable, should this
function accept 2 and translate it into the hardware's automatic mode?

> +
> +			entry = applesmc_get_entry_by_key(FANS_MANUAL);
> +			if (IS_ERR(entry))
> +				return PTR_ERR(entry);

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260711075754.11358-1-fourdollars@debian.org?part=3

  reply	other threads:[~2026-07-11  8:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 12:32 [PATCH 0/1] hwmon: (applesmc) Convert to hwmon_device_register_with_info Shih-Yuan Lee
2026-07-10 12:32 ` [PATCH 1/1] " Shih-Yuan Lee
2026-07-10 12:47   ` sashiko-bot
2026-07-10 14:01   ` Guenter Roeck
2026-07-10 21:10     ` Armin Wolf
2026-07-10 22:28       ` Guenter Roeck
2026-07-11  2:51         ` Shih-Yuan Lee (FourDollars)
2026-07-11  3:36 ` [PATCH v2 0/1] " Shih-Yuan Lee
2026-07-11  3:37   ` [PATCH v2 1/1] " Shih-Yuan Lee
2026-07-11  3:47     ` sashiko-bot
2026-07-11  5:39 ` [PATCH v3 0/1] " Shih-Yuan Lee
2026-07-11  5:39   ` [PATCH v3 1/1] " Shih-Yuan Lee
2026-07-11  5:52     ` sashiko-bot
2026-07-11  6:06 ` [PATCH v4 0/1] " Shih-Yuan Lee
2026-07-11  6:06   ` [PATCH v4 1/1] " Shih-Yuan Lee
2026-07-11  6:17     ` sashiko-bot
2026-07-11  7:57 ` [PATCH v5 0/3] " Shih-Yuan Lee
2026-07-11  7:57   ` [PATCH v5 1/3] hwmon: (applesmc) Cache fan positions during register initialization Shih-Yuan Lee
2026-07-11  8:06     ` sashiko-bot
2026-07-11  7:57   ` [PATCH v5 2/3] hwmon: (applesmc) Fix lockless cache validation data race Shih-Yuan Lee
2026-07-11  8:10     ` sashiko-bot
2026-07-11  7:57   ` [PATCH v5 3/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info Shih-Yuan Lee
2026-07-11  8:12     ` sashiko-bot [this message]
2026-07-11  9:33 ` [PATCH v6 0/3] " Shih-Yuan Lee
2026-07-11  9:33   ` [PATCH v6 1/3] hwmon: (applesmc) Cache fan positions during register initialization Shih-Yuan Lee
2026-07-11  9:42     ` sashiko-bot
2026-07-11  9:33   ` [PATCH v6 2/3] hwmon: (applesmc) Fix lockless cache validation data race Shih-Yuan Lee
2026-07-11  9:43     ` sashiko-bot
2026-07-11  9:33   ` [PATCH v6 3/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info Shih-Yuan Lee
2026-07-11  9:42     ` sashiko-bot

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=20260711081237.A8A121F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fourdollars@debian.org \
    --cc=linux-hwmon@vger.kernel.org \
    --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