From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: "Ihor Odainyi" <pv4k@odayny.com>,
"Antoine Sidem" <sidemantoine@gmail.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 04/14] iio/light: add new driver for macsmc
Date: Fri, 04 Dec 2026 13:47:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-249895@kernel.org> (raw)
In-Reply-To: <20261204131619.5059-5-atharvatiwarilinuxdev@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] iio: light: notifier registered before
devm_iio_device_register() causes UAF
- [Medium] iio: light: unconditional RIGHT_LIGHT channel and missing
ALV1 validation
- [Medium] iio: light: macsmc-light exposes unitless raw SMC counts as
IIO_LIGHT
- [Low] iio: light: Kconfig module name mismatch and MACSMC_ACPI
dependency
- [Low] mfd: macsmc: literal -1 passed to devm_mfd_add_devices() for
light cell
--
commit e9ed4cb9e8bdd5a53203bb98eb77007e4876b53e
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
iio/light: add new driver for macsmc
This commit adds an IIO ambient light sensor driver for Apple SMC
(macsmc-light) exposing left and right channels, and registers its MFD
cell from macsmc-core when the ALV0 key is present.
> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index 462fff1ddef20..f84707edc6772 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -457,6 +457,17 @@ config LV0104CS
> To compile this driver as a module, choose M here:
> the module will be called lv0104cs.
>
> +config MACSMC_LIGHT
> + tristate "Apple SMC Light Sensor"
> + depends on MACSMC_ACPI
> + help
> + Say Y here if you have a Intel-based Mac. and you
> + want support for light sensors.
> +
> + To compile this driver as a module, choose M here:
> + the module will be called macsmc_light
[Severity: Low]
The Makefile builds macsmc-light.o, so the help text should say
macsmc-light (with a hyphen and trailing period) rather than
macsmc_light.
Also, macsmc-light only uses architecture-independent interfaces from
MFD_MACSMC_CORE. Should this depend on MFD_MACSMC_CORE (or MACSMC_ACPI
|| (MFD_MACSMC_CORE && COMPILE_TEST)) like the sibling macsmc drivers so
it can be compile-tested on non-x86 builds?
> diff --git a/drivers/iio/light/macsmc-light.c b/drivers/iio/light/macsmc-light.c
> new file mode 100644
> index 0000000000000..12d88035ad746
> --- /dev/null
> +++ b/drivers/iio/light/macsmc-light.c
[ ... ]
> +static const struct iio_chan_spec macsmc_light_channels[] = {
> + {
> + .type = IIO_LIGHT,
> + .channel = LEFT_LIGHT,
> + .indexed = 1,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .event_spec = macsmc_light_events,
> + .num_event_specs = ARRAY_SIZE(macsmc_light_events),
> + },
> + {
> + .type = IIO_LIGHT,
> + .channel = RIGHT_LIGHT,
> + .indexed = 1,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .event_spec = macsmc_light_events,
> + .num_event_specs = ARRAY_SIZE(macsmc_light_events),
> + },
> +};
[Severity: Medium]
Should these channels use IIO_INTENSITY instead of IIO_LIGHT?
Per Documentation/ABI/testing/sysfs-bus-iio, IIO_LIGHT
(in_illuminanceY_raw) must report illuminance in lux after scale and
offset. macsmc_light_read_raw() instead returns uncalibrated, unit-less
raw SMC counts with no scale attribute.
Exposing unit-less counts under in_illuminanceY_raw locks in wrong units
for userspace. Without a lux conversion or scale factor, IIO_INTENSITY
(in_intensityY_raw) is the documented type for unit-less light readings.
[ ... ]
> + ret = apple_smc_get_key_info(drv->smc, SMC_KEY(ALV0), &info);
> + if (ret < 0)
> + return -ENODEV;
> +
> + if (info.size < 3 || info.size > 10)
> + return -ENODEV;
> +
> + drv->size = info.size;
> + drv->single_sensor = info.size == 10;
[Severity: Medium]
Does macsmc_light_probe() need to check ALV1 separately and register
only one channel when a single sensor is present?
On single-sensor Macs (10-byte ALV0), registering both channels exposes
a nonexistent right channel that always returns 0 and never emits
events.
When ALV0 is 3 to 9 bytes on hardware without a matching-length ALV1,
reading RIGHT_LIGHT with drv->size fails or reads past ALV1 while
macsmc_light_event() still pushes RIGHT_LIGHT events. Querying ALV1 in
probe and sizing indio_dev->num_channels accordingly would avoid both.
> + drv->indio_dev = indio_dev;
> + drv->nb.notifier_call = macsmc_light_event;
> + ret = blocking_notifier_chain_register(drv->smc->event_handlers, &drv->nb);
> + if (ret)
> + return ret;
> +
> + ret = devm_add_action_or_reset(dev, macsmc_light_unregister_notifier, drv);
> + if (ret)
> + return ret;
> +
> + indio_dev->name = "macsmc-light";
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->info = &macsmc_light_info;
> + indio_dev->channels = macsmc_light_channels;
> + indio_dev->num_channels = ARRAY_SIZE(macsmc_light_channels);
> +
> + return devm_iio_device_register(dev, indio_dev);
[Severity: Medium]
Can registering the SMC notifier before devm_iio_device_register() cause
a use-after-free on probe failure and inverted teardown on unbind?
apple_smc_acpi_probe() enables SMC interrupts before adding MFD
children, so SMC_INT_ALS_CHANGE can invoke macsmc_light_event() while
devm_iio_device_register() is still running or unwinding:
CPU0 CPU1
macsmc_light_probe()
blocking_notifier_chain_register()
devm_iio_device_register()
iio_device_register_eventset()
event_interface = ev_int
... (cdev_device_add() fails)
iio_device_unregister_eventset()
apple_smc_acpi_notifier_work()
macsmc_light_event()
iio_push_event()
ev_int = ...->event_interface
kfree(ev_int)
event_interface = NULL
iio_event_enabled(ev_int)
<-- use-after-free
On normal unbind, devres LIFO order also runs iio_device_unregister()
before macsmc_light_unregister_notifier(), leaving the notifier pushing
events after the IIO device is torn down. Registering the notifier
after devm_iio_device_register() succeeds fixes both.
> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index 1c14698285456..6014df4fe1c0a 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c
[ ... ]
> @@ -158,6 +162,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
> return ret;
> }
>
> + if (apple_smc_key_exists(smc, SMC_KEY(ALV0))) {
> + ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_light,
> + ARRAY_SIZE(apple_smc_acpi_light), NULL, 0, NULL);
> + if (ret < 0)
> + return ret;
> + }
[Severity: Low]
This isn't a bug, but devm_mfd_add_devices() here passes a literal -1
instead of PLATFORM_DEVID_AUTO (or PLATFORM_DEVID_NONE if a fixed
single-instance name is required).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=4
next prev parent reply other threads:[~2026-12-04 13:47 UTC|newest]
Thread overview: 47+ 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 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 [this message]
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 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 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys 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-249895@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=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