From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: "Ihor Odainyi" <pv4k@odayny.com>,
"Antoine Sidem" <sidemantoine@gmail.com>,
"Aditya Garg" <aditya.garg@linux.dev>,
"Andre Eikmeyer" <dev@deq.rocks>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
"Linus Walleij" <linusw@kernel.org>,
"Bartosz Golaszewski" <brgl@kernel.org>,
"Sven Peter" <sven@kernel.org>, "Janne Grunau" <j@jannau.net>,
"Neal Gompa" <neal@gompa.dev>,
"Guenter Roeck" <linux@roeck-us.net>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>, "Lee Jones" <lee@kernel.org>,
"Pavel Machek" <pavel@kernel.org>,
"Griffin Kroah-Hartman" <griffin@kroah.com>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Sebastian Reichel" <sre@kernel.org>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Wim Van Sebroeck" <wim@linux-watchdog.org>,
"Jarkko Sakkinen" <jarkko@kernel.org>,
"Mimi Zohar" <zohar@linux.ibm.com>,
"Roberto Sassu" <roberto.sassu@huawei.com>,
"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>,
"Eric Snowberg" <eric.snowberg@oracle.com>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-pci@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org,
mfd@lists.linux.dev, linux-rtc@vger.kernel.org,
linux-watchdog@vger.kernel.org, keyrings@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon
Date: Fri, 04 Dec 2026 14:48:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-250014@kernel.org> (raw)
In-Reply-To: <20261204131619.5059-14-atharvatiwarilinuxdev@gmail.com>
Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] hwmon: macsmc: NULL pointer dereference in DT sensor label
handling
- [High] hwmon: macsmc: redundant SMC probes cause multi-minute PIO
probe stalls
- [Medium] hwmon: macsmc: uninitialized count read in
macsmc_hwmon_populate_sensors_acpi()
- [Medium] hwmon: macsmc: heap OOB write in
macsmc_hwmon_register_sensors_acpi()
- [Medium] hwmon: macsmc: invalid sensor keys and missing key validation
on ACPI
- [Medium] hwmon: macsmc: unvalidated F%dID read and fatal optional fan
key errors
- [Medium] hwmon: macsmc: missing big-endian conversion for integer keys
on ACPI
- [Medium] hwmon: macsmc_hwmon_resume() skips FS! and target restore,
uses legacy PM
- [Low] hwmon: macsmc: outdated docs, MODULE_DESCRIPTION, and whitespace
changes
- [Low] hwmon: macsmc: u16/__be16 mismatch in
macsmc_hwmon_write_old_fan_manual()
- [Low] hwmon: macsmc-hwmon uses deprecated legacy
platform_driver.resume callback
--
commit cda7f94f03b9c07639e3fb001f94e54d739b4e68
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
hwmon: add support for x86 macs in macsmc-hwmon
This commit extends macsmc-hwmon to support Intel Macs over ACPI by
adding static sensor descriptor tables, ACPI sensor and fan discovery,
legacy FS! manual fan control, and a resume callback.
> diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c
> index 14b68cf8c283e..d531eb4122f89 100644
> --- a/drivers/hwmon/macsmc-hwmon.c
> +++ b/drivers/hwmon/macsmc-hwmon.c
[ ... ]
> @@ -47,7 +52,7 @@ MODULE_PARM_DESC(fan_control,
> struct macsmc_hwmon_sensor {
> struct apple_smc_key_info info;
> smc_key macsmc_key;
> - char label[MAX_LABEL_LENGTH];
> + char *label;
> u32 attrs;
> };
[Severity: High]
Does changing label to a char * pointer cause a NULL pointer dereference on
Apple Silicon Device Tree systems?
macsmc_hwmon_populate_sensors() zero-allocates each sensor array with
devm_kcalloc(), leaving sensor->label NULL. When a Device Tree sensor node
has a label property, macsmc_hwmon_create_sensor() calls
strscpy_pad(sensor->label, label, sizeof(sensor->label)), writing to NULL
with a pointer size; when a node omits label, macsmc_hwmon_populate_sensors()
dereferences NULL via if (*sensor->label).
Making label (and macsmc_sensor_desc.name) const char *, assigning the DT
label pointer directly (or via devm_kstrdup_const()), and checking
sensor->label && *sensor->label would avoid this.
[ ... ]
> @@ -599,6 +605,25 @@ static int macsmc_hwmon_read_fan(struct macsmc_hwmon *hwmon, u32 attr, int chan,
> }
> }
>
> +static int macsmc_hwmon_write_old_fan_manual(struct macsmc_hwmon *hwmon, u8 val, int channel)
> +{
> + int ret;
> + u16 buf;
> +
> + ret = apple_smc_read_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), &buf);
> + if (ret)
> + return ret;
> +
> + buf = be16_to_cpu(buf);
> +
> + if (val)
> + buf |= BIT(channel);
> + else
> + buf &= ~BIT(channel);
> +
> + return apple_smc_write_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), cpu_to_be16(buf));
> +}
[Severity: Low]
Will buf trigger sparse endianness warnings here? buf is declared as
host-endian u16, passed directly to be16_to_cpu(), and then cpu_to_be16(buf)
is passed to apple_smc_write_u16(), which takes a plain u16. Reading and
writing a __be16 variable via apple_smc_read() and apple_smc_write() would
keep endianness annotations consistent.
[ ... ]
> +static int macsmc_hwmon_create_sensor_acpi(struct apple_smc *smc,
> + struct macsmc_hwmon_sensor *sensor, smc_key key, char *name, u32 attrs)
> +{
> + int ret;
> +
> + ret = apple_smc_get_key_info(smc, key, &sensor->info);
> + if (ret)
> + return ret;
> +
> + sensor->macsmc_key = key;
> + sensor->label = name;
> + sensor->attrs = attrs;
> +
> + return 0;
> +}
[Severity: Medium]
Can this register unreadable keys, unsupported SMC types, or non-sensor keys
as hwmon attributes and thermal zones?
macsmc_hwmon_create_sensor_acpi() never checks APPLE_SMC_READABLE or whether
sensor->info.type_code is handled by macsmc_hwmon_read_key(), so keys with
types such as flag, hex_, or ch8* fail every read with -EOPNOTSUPP or -EIO.
The static tables also include non-sensor entries such as audio scratchpads
(MST1, MST2), power limits and throttles (MSTc, MSTg, PZ0T..PZ5T), and
non-temperature keys (TCFC, TMBS, TH0e) in temp_sensors[], which are exposed
as kernel thermal zones because HWMON_C_REGISTER_TZ is set.
[ ... ]
> +static int macsmc_hwmon_create_fan_acpi(struct apple_smc *smc,
> + struct macsmc_hwmon_fan *fan, int num)
> +{
> + const char num_char = num + '0';
> + int ret;
> +
> + ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->now,
> + __SMC_KEY('F', num_char, 'A', 'c'), NULL, 0);
> + if (ret)
> + return ret;
> +
> + if (apple_smc_key_exists(smc, __SMC_KEY('F', num_char, 'I', 'D'))) {
> + char buf[17];
> +
> + ret = apple_smc_read(smc, __SMC_KEY('F', num_char, 'I', 'D'), buf, 16);
> + if (ret < 0)
> + return ret;
> +
> + buf[16] = '\0';
> + snprintf(fan->label, sizeof(fan->label), "%s", buf + 4);
> + } else
> + snprintf(fan->label, sizeof(fan->label), "Fan %d", num);
> +
> + ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->min,
> + __SMC_KEY('F', num_char, 'M', 'n'), NULL, 0);
> + if (ret)
> + return ret;
> +
> + ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->max,
> + __SMC_KEY('F', num_char, 'M', 'x'), NULL, 0);
> + if (ret)
> + return ret;
> +
> + ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->set,
> + __SMC_KEY('F', num_char, 'T', 'g'), NULL, 0);
> + if (ret)
> + return ret;
[Severity: Medium]
Can a short or unreadable F%dID key copy stale MMIO bytes or abort the entire
hwmon probe?
apple_smc_key_exists() discards info.size, so apple_smc_read() requests 16
bytes without checking that F%dID is 16 bytes long; apple_smc_acpi_mmio_read()
copies len bytes unconditionally from SRAM, and PIO mode times out with -EIO.
On read failure, or if any of F%dMn, F%dMx, or F%dTg is absent, returning ret
aborts macsmc_hwmon_probe() completely instead of falling back to "Fan %d" or
treating those keys as optional like macsmc_hwmon_create_fan() does.
[ ... ]
> +static int macsmc_hwmon_register_sensors_acpi(
> + struct macsmc_hwmon *hwmon,
> + struct macsmc_hwmon_sensors *sensors,
> + const struct macsmc_sensor_desc *descs,
> + size_t num_descs,
> + u32 attrs)
> +{
> + size_t count = 0;
> + size_t i;
> + int ret;
> +
> + for (i = 0; i < num_descs; i++) {
> + if (apple_smc_key_exists(hwmon->smc, descs[i].key))
> + count++;
> + }
> +
> + if (!count)
> + return 0;
> +
> + sensors->sensors = devm_kcalloc(hwmon->dev, count,
> + sizeof(*sensors->sensors),
> + GFP_KERNEL);
> + if (!sensors->sensors)
> + return -ENOMEM;
> +
> + sensors->count = 0;
> +
> + for (i = 0; i < num_descs; i++) {
> + if (!apple_smc_key_exists(hwmon->smc, descs[i].key))
> + continue;
> +
> + ret = macsmc_hwmon_create_sensor_acpi(hwmon->smc,
> + &sensors->sensors[sensors->count],
> + descs[i].key,
> + descs[i].name,
> + attrs);
> + if (ret)
> + return ret;
> +
> + sensors->count++;
> + }
> +
> + return 0;
> +}
[Severity: Medium]
Can a transient SMC timeout cause a heap out-of-bounds write past
sensors->sensors?
apple_smc_key_exists() treats transient -EIO timeouts the same as missing
keys. If a key query fails during the counting pass and succeeds during the
second pass, sensors->count exceeds the allocated count without any bounds
check, overflowing sensors->sensors.
[Severity: High]
Will probing all 558 static keys twice over live SMC hardware stall boot for
minutes on PIO Intel Macs?
This function queries every key twice via apple_smc_key_exists() and a third
time in macsmc_hwmon_create_sensor_acpi() for present keys
(macsmc_hwmon_create_fan_acpi() similarly double-queries F%dMd). On PIO
Macs, apple_smc_acpi_port_read() detects nonexistent keys only by timing out
for 1,000 ms in apple_smc_acpi_port_wait() and disabling SMC interrupts on
the first miss, so probing hundreds of absent keys twice stalls probe for
over 15 minutes.
Enumerating or binary-searching the sorted SMC key table via
apple_smc_get_key_by_index() (like applesmc.c does) would avoid probing
missing keys.
> +static int macsmc_hwmon_populate_sensors_acpi(struct macsmc_hwmon *hwmon)
> +{
> + int ret, i;
> + u8 count;
> +
> + ret = apple_smc_read_u8(hwmon->smc, SMC_KEY(FNum), &count);
> + if (count && !ret) {
[Severity: Medium]
Does if (count && !ret) read uninitialized stack variable count when reading
FNum fails?
On error, both apple_smc_acpi_mmio_read() and apple_smc_acpi_port_read()
return without writing to the output buffer, leaving count uninitialized on
fanless Macs without FNum and triggering KMSAN uninit-value reports.
Checking if (!ret && count) avoids this.
[ ... ]
> + if (hwmon->smc->is_acpi)
> + ret = macsmc_hwmon_populate_sensors_acpi(hwmon);
> + else
> + ret = macsmc_hwmon_populate_sensors(hwmon, hwmon->dev->of_node);
[Severity: Medium]
Will Intel Mac sensors backed by ui16, si16, ui32, or si32 SMC keys return
byte-swapped values?
Multi-byte integer keys on Intel ACPI SMCs are big-endian (as handled for FS!
in macsmc_hwmon_write_old_fan_manual() and in macsmc-power.c), but
macsmc_hwmon_read_key() reads them in host byte order without converting when
smc->is_acpi is true:
drivers/hwmon/macsmc-hwmon.c:macsmc_hwmon_read_key() {
...
case __SMC_KEY('u', 'i', '1', '6'): {
u16 ui16 = 0;
ret = apple_smc_read_u16(smc, sensor->macsmc_key, &ui16);
if (ret)
return ret;
*val = (s64)ui16 * scale;
break;
}
...
}
The same applies to si16, ui32, and si32, so any ACPI sensor using those
types reports garbage on little-endian x86 hosts.
[ ... ]
> +static int macsmc_hwmon_resume(struct platform_device *pdev)
> +{
> + struct macsmc_hwmon *hwmon = dev_get_drvdata(&pdev->dev);
> +
> + if (hwmon->smc->is_acpi && !hwmon->fan.has_old_manual) {
> + int idx;
> + int ret;
> +
> + for (idx = 0; idx < hwmon->fan.count; idx++)
> + if (hwmon->fan.fans[idx].manual) {
> + ret = macsmc_hwmon_write_key(hwmon->smc,
> + &hwmon->fan.fans[idx].mode, 1);
> + if (ret < 0) {
> + dev_warn(&pdev->dev,
> + "Unable to reenable fan manual, disabling\n");
> + hwmon->fan.fans[idx].manual = false;
> + }
> + }
> +
> + }
> +
> + return 0;
> +}
[Severity: Medium]
Does macsmc_hwmon_resume() leave fan control state desynchronized with the
SMC after suspend or hibernation?
Checking !hwmon->fan.has_old_manual skips older Intel Macs that use FS!, so
fans[idx].manual stays true in memory after the SMC resets to automatic mode
and later fanX_target writes will not re-set FS! until userspace writes 0
first. On newer Intel Macs, re-enabling manual mode (F%dMd = 1) without
restoring the saved F%dTg target speed locks fans in manual mode at the SMC's
post-sleep or post-boot default target.
[ ... ]
> static struct platform_driver macsmc_hwmon_driver = {
> .probe = macsmc_hwmon_probe,
> + .resume = macsmc_hwmon_resume,
> .driver = {
> .name = "macsmc-hwmon",
> .of_match_table = macsmc_hwmon_of_table,
[Severity: Low]
Should this use DEFINE_SIMPLE_DEV_PM_OPS() with .driver.pm = pm_sleep_ptr()
instead of the deprecated legacy platform_driver.resume callback? Using
dev_pm_ops matches the other macsmc drivers in this series and allows the
compiler to drop macsmc_hwmon_resume() when CONFIG_PM_SLEEP is disabled.
[ ... ]
> MODULE_DESCRIPTION("Apple Silicon SMC hwmon driver");
> MODULE_AUTHOR("James Calligeros <jcalligeros99@gmail.com>");
> MODULE_LICENSE("Dual MIT/GPL");
> +MODULE_ALIAS("platform:macsmc-hwmon");
[Severity: Low]
This isn't a bug, but Documentation/hwmon/macsmc-hwmon.rst,
MODULE_DESCRIPTION, and the file header comment still describe the driver as
Apple Silicon only. The patch also includes unrelated whitespace changes in
macsmc_hwmon_write_f32(), macsmc_hwmon_is_visible(), and
macsmc_hwmon_populate_sensors() that misalign continuation lines away from
the opening parenthesis.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=13
next prev parent reply other threads:[~2026-12-04 14:48 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
2026-12-04 13:56 ` sashiko-bot
2026-12-04 14:07 ` Andy Shevchenko
2026-12-04 16:45 ` Sven Peter
2026-12-04 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
2026-12-04 13:58 ` sashiko-bot
2026-12-04 14:19 ` Andy Shevchenko
2026-12-04 14:52 ` Aditya Garg
2026-12-04 17:23 ` Andy Shevchenko
2026-12-04 18:34 ` Aditya Garg
2026-12-04 19:57 ` Atharva Tiwari
2026-12-04 20:23 ` Andy Shevchenko
2026-12-04 13:12 ` [PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
2026-12-04 13:48 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
2026-12-04 13:47 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
2026-12-04 14:11 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
2026-12-04 14:07 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
2026-12-04 14:12 ` Andy Shevchenko
2026-12-04 14:48 ` Aditya Garg
2026-12-04 17:06 ` Andy Shevchenko
2026-12-04 17:10 ` Aditya Garg
2026-12-04 17:18 ` Andy Shevchenko
2026-12-04 17:26 ` Sven Peter
2026-12-04 14:16 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-12-04 14:11 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
2026-12-04 14:27 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
2026-12-04 14:39 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
2026-12-04 14:08 ` Andy Shevchenko
2026-12-04 14:56 ` Aditya Garg
2026-12-04 17:14 ` Andy Shevchenko
2026-12-04 18:51 ` Aditya Garg
2026-12-04 20:02 ` Andy Shevchenko
2026-12-04 20:13 ` Andy Shevchenko
2026-12-04 14:25 ` sashiko-bot
2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
2026-12-04 14:37 ` sashiko-bot
2026-12-04 18:44 ` Guenter Roeck
2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
2026-12-04 14:48 ` sashiko-bot [this message]
2026-12-04 18:45 ` Guenter Roeck
2026-12-04 20:13 ` Jarkko Sakkinen
2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
2026-12-04 13:40 ` Sasha Finkelstein
2026-12-04 19:43 ` Atharva Tiwari
2026-12-04 14:48 ` sashiko-bot
2026-12-04 14:20 ` [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Andy Shevchenko
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=sashiko-outbox-250014@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aditya.garg@linux.dev \
--cc=alexandre.belloni@bootlin.com \
--cc=andy@kernel.org \
--cc=atharvatiwarilinuxdev@gmail.com \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=brgl@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=dev@deq.rocks \
--cc=dlechner@baylibre.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=eric.snowberg@oracle.com \
--cc=griffin@kroah.com \
--cc=hansg@kernel.org \
--cc=hpa@zytor.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=j@jannau.net \
--cc=jarkko@kernel.org \
--cc=jic23@kernel.org \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=lee@kernel.org \
--cc=lenb@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mfd@lists.linux.dev \
--cc=mingo@redhat.com \
--cc=neal@gompa.dev \
--cc=nuno.sa@analog.com \
--cc=paul@paul-moore.com \
--cc=pavel@kernel.org \
--cc=pv4k@odayny.com \
--cc=rafael@kernel.org \
--cc=roberto.sassu@huawei.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=serge@hallyn.com \
--cc=sidemantoine@gmail.com \
--cc=sre@kernel.org \
--cc=sven@kernel.org \
--cc=tglx@kernel.org \
--cc=wim@linux-watchdog.org \
--cc=x86@kernel.org \
--cc=zohar@linux.ibm.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