From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: "Ihor Odainyi" <pv4k@odayny.com>,
"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 05/14] iio/accel: add driver for apple SMS
Date: Fri, 04 Dec 2026 14:11:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-249934@kernel.org> (raw)
In-Reply-To: <20261204131619.5059-6-atharvatiwarilinuxdev@gmail.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] iio: accel: macsmc-accel: missing event config callbacks in
macsmc_accel_info
- [Medium] iio: accel: macsmc_accel_probe() enables notifier before IIO
registration
- [Medium] iio: accel: macsmc_accel_dev_init() ignores SMC errors and
misorders poll
- [Medium] iio: accel: macsmc-accel: undocumented orientation change
event ABI
- [Medium] mfd: macsmc: probing absent MOCN via apple_smc_key_exists()
stalls PIO boot
- [Low] iio: accel: macsmc-accel: s16 passed to be16_to_cpu() in
macsmc_accel_read()
- [Low] iio: accel: macsmc-accel: Makefile order, MFD cell ID, and
subject conventions
--
commit 72edf11305348abc7eba7049f44352095cfc9e6d
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
iio/accel: add driver for apple SMS
This commit adds an IIO accelerometer driver for the Apple SMC Sudden
Motion Sensor (reporting X/Y/Z axes and drop, orientation, and shock
events) and registers it from the ACPI SMC MFD core when the MOCN key
exists.
> diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
> index fa440a8592839..52fe661dec666 100644
> --- a/drivers/iio/accel/Makefile
> +++ b/drivers/iio/accel/Makefile
> @@ -54,6 +54,7 @@ obj-$(CONFIG_KXSD9) += kxsd9.o
> obj-$(CONFIG_KXSD9_SPI) += kxsd9-spi.o
> obj-$(CONFIG_KXSD9_I2C) += kxsd9-i2c.o
> obj-$(CONFIG_MC3230) += mc3230.o
> +obj-$(CONFIG_MACSMC_ACCEL) += macsmc-accel.o
[Severity: Low]
This isn't a bug, but CONFIG_MACSMC_ACCEL is placed after CONFIG_MC3230,
breaking the alphabetical ordering in this Makefile. Similarly, the new
devm_mfd_add_devices() call in drivers/mfd/macsmc-core.c passes -1 instead
of PLATFORM_DEVID_AUTO (or PLATFORM_DEVID_NONE), and the commit subject
uses "iio/accel:" instead of the standard "iio: accel:" prefix.
> diff --git a/drivers/iio/accel/macsmc-accel.c b/drivers/iio/accel/macsmc-accel.c
> new file mode 100644
> index 0000000000000..79891fd13c56a
> --- /dev/null
> +++ b/drivers/iio/accel/macsmc-accel.c
[ ... ]
> +static int macsmc_accel_read(struct macsmc_accel *drv, smc_key key, s16 *p)
> +{
> + int ret;
> +
> + ret = apple_smc_read_s16(drv->smc, key, p);
> + if (ret < 0)
> + return ret;
> +
> + *p = (s16)be16_to_cpu(*p);
> + return 0;
> +}
[Severity: Low]
Does passing host-endian s16 *p directly to be16_to_cpu() trigger a sparse
endianness warning? __be16_to_cpu() expects a restricted __be16 value, so
reading into a local __be16 (e.g., via apple_smc_read()) and converting
with be16_to_cpu() into *p keeps the endianness types sparse-clean.
> +static int macsmc_accel_dev_init(struct macsmc_accel *drv)
> +{
> + int ret, total;
> + u16 buf, write_value;
> +
> + ret = apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf);
> + if (ret < 0)
> + return ret;
> +
> + /* 0xE0 enables the interrupts and the actual motion sensors */
> + write_value = buf | 0xE0;
> +
> + for (total = 0; total < 100; total++) {
> + ret = apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf);
> + if (!ret && (buf & 0xE0) == 0xE0)
> + return 0;
> +
> + apple_smc_write_u16(drv->smc, SMC_KEY(MOCN), write_value);
> + msleep(50);
> + }
> +
> + return -ENODEV;
> +}
[Severity: Medium]
Can this retry loop stall probe or hibernation restore for minutes while
holding smc->mutex?
Both read errors from apple_smc_read_u16() and the return value of
apple_smc_write_u16() are ignored across 100 iterations. Each SMC
transaction holds smc->mutex and can wait up to SMC_TIMEOUT_MS (1000 ms),
turning persistent timeouts into a multi-minute stall for sibling drivers.
The loop also re-reads MOCN on iteration 0 without checking the initial
read for (buf & 0xE0) == 0xE0, and returns -ENODEV after the 100th write
and sleep without checking whether that final write took effect. Checking
the initial read, propagating I/O errors (or bounding wall-clock time),
and doing write, sleep, then read in the loop avoids these issues.
[ ... ]
> + case SMC_INT_SMS_ORIENTATION:
> + code = IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z,
> + IIO_EV_TYPE_CHANGE, IIO_EV_DIR_NONE);
> + break;
[Severity: Medium]
As reported by Jonathan Cameron on RFC [1], what acceleration condition
triggers SMC_INT_SMS_ORIENTATION? No other IIO_ACCEL driver uses
IIO_EV_TYPE_CHANGE, and in_accel_x|y|z_change_en is undocumented in
Documentation/ABI/testing/sysfs-bus-iio, so userspace cannot interpret it.
[ ... ]
> +static const struct iio_event_spec macsmc_accel_drop_events[] = {
> + {
> + .type = IIO_EV_TYPE_THRESH,
> + .dir = IIO_EV_DIR_FALLING,
> + .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> + },
> +};
> +
> +static const struct iio_event_spec macsmc_accel_any_axis_events[] = {
> + {
> + .type = IIO_EV_TYPE_THRESH,
> + .dir = IIO_EV_DIR_RISING,
> + .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> + },
> + {
> + .type = IIO_EV_TYPE_CHANGE,
> + .dir = IIO_EV_DIR_NONE,
> + .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> + },
> +};
[ ... ]
> +static const struct iio_info macsmc_accel_info = {
> + .read_raw = macsmc_accel_read_raw
> +};
[Severity: Medium]
Will all three exported *_en event sysfs attributes unconditionally fail
with -EINVAL?
Setting BIT(IIO_EV_INFO_ENABLE) registers the *_en attributes via
iio_ev_state_show() and iio_ev_state_store(), which both return -EINVAL
when read_event_config and write_event_config are NULL in
macsmc_accel_info. This either needs those callbacks implemented or
BIT(IIO_EV_INFO_ENABLE) omitted if the events are always enabled.
[ ... ]
> + ret = macsmc_accel_dev_init(drv);
> + if (ret)
> + return ret;
> +
> + drv->indio_dev = indio_dev;
> + drv->nb.notifier_call = macsmc_accel_event;
> + ret = blocking_notifier_chain_register(drv->smc->event_handlers, &drv->nb);
> + if (ret)
> + return ret;
> +
> + ret = devm_add_action_or_reset(&pdev->dev, macsmc_accel_unregister_notifier, drv);
> + if (ret)
> + return ret;
> +
> + platform_set_drvdata(pdev, drv);
> +
> + indio_dev->name = "macsmc-accel";
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->info = &macsmc_accel_info;
> + indio_dev->channels = macsmc_accel_channels;
> + indio_dev->num_channels = ARRAY_SIZE(macsmc_accel_channels);
> +
> + return devm_iio_device_register(&pdev->dev, indio_dev);
> +}
[Severity: Medium]
Can macsmc_accel_event() hit a use-after-free on ev_int if
devm_iio_device_register() fails?
The parent SMC IRQ and notifier work are already active before
macsmc_accel_probe() runs, and macsmc_accel_dev_init() enables motion
sensor interrupts before the IIO device is registered. If a late step in
__iio_device_register() fails, it frees ev_int before devres unregisters
the notifier:
CPU0 CPU1 (kworker)
macsmc_accel_probe()
macsmc_accel_dev_init()
blocking_notifier_chain_register()
devm_iio_device_register()
iio_device_register_eventset()
iio_dev_opaque->event_interface = ev_int
apple_smc_acpi_notifier_work()
macsmc_accel_event()
iio_push_event()
ev_int = ...->event_interface
... (error unwind)
kfree(ev_int)
iio_dev_opaque->event_interface = NULL
iio_event_enabled(ev_int)
<-- use-after-free
If the freed slab object is reused with its enabled bit set, kfifo_put()
and wake_up_poll() can also corrupt memory. Registering the IIO device
before registering the SMC notifier closes this window and ensures the
notifier is torn down before iio_device_unregister() on remove.
> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index 6014df4fe1c0a..6567d2f1f8f53 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c
[ ... ]
> @@ -169,6 +173,12 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
> return ret;
> }
>
> + if (apple_smc_key_exists(smc, SMC_KEY(MOCN))) {
> + ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_accel,
> + ARRAY_SIZE(apple_smc_acpi_accel), NULL, 0, NULL);
> + if (ret < 0)
> + return ret;
> + }
> } else
> ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
> ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);
[Severity: Medium]
Does probing SMC_KEY(MOCN) via apple_smc_key_exists() add a 1-second
synchronous boot stall on PIO-based Intel Macs without a motion sensor?
On PIO Macs, apple_smc_acpi_port_get_key_info() has no non-timeout error
check, so an absent key only fails after apple_smc_acpi_port_wait() polls
SMC_IO_CMD_PORT for the full SMC_TIMEOUT_MS (1000 ms). Binary searching
via GET_KEY_BY_INDEX (like applesmc_has_key()) avoids this timeout.
[1] https://lore.kernel.org/r/20261101013540.3af16ea0@jic23-hlaptop
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=5
next prev parent reply other threads:[~2026-12-04 14:11 UTC|newest]
Thread overview: 57+ 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 [this message]
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 14:42 ` Sasha Finkelstein
2026-12-04 19:41 ` Atharva Tiwari
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
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-249934@kernel.org \
--to=sashiko-bot@kernel.org \
--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=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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.