From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: "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: [RFC PATCH 01/14] treewide: Add backend for macsmc
Date: Thu, 29 Oct 2026 09:20:09 +0000 [thread overview]
Message-ID: <sashiko-outbox-189026@kernel.org> (raw)
In-Reply-To: <20261029085504.3547-2-atharvatiwarilinuxdev@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mfd: macsmc: Kconfig split disables Apple SMC drivers in arm64 defconfig
- [Medium] mfd: macsmc: missing notification cleanup on apple_smc_probe() error
- [Low] mfd: macsmc: endianness type mismatch in apple_smc_probe() #KEY read
--
commit f3824312f6532aec08553002200ae557d8b3b0da
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
treewide: Add backend for macsmc
This commit splits the Apple SMC driver into a core MFD driver
(drivers/mfd/macsmc-core.c) and an RTKit backend driver
(drivers/soc/apple/macsmc-rtkit.c) so that additional SMC backends such as
ACPI on Intel Macs can share the core and sub-drivers.
[ ... ]
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 87ed55c155f03..c58cc3315f22a 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -339,24 +339,15 @@ config MFD_LOCHNAGAR
> help
> Support for Cirrus Logic Lochnagar audio development board.
>
> -config MFD_MACSMC
> - tristate "Apple Silicon System Management Controller (SMC)"
> - depends on ARCH_APPLE || COMPILE_TEST
> - depends on OF
> - depends on APPLE_RTKIT
> +config MFD_MACSMC_CORE
> + tristate "Apple System Management Controller (SMC) Core"
> select MFD_CORE
[Severity: High]
Does removing this symbol without updating arch/arm64/configs/defconfig or
providing defaults cause a regression where all Apple SMC drivers become
disabled on arm64 builds?
In arch/arm64/configs/defconfig:
CONFIG_MFD_MACSMC=m
With that symbol removed and neither the new core option nor the new rtkit
backend option in drivers/soc/apple/Kconfig having a default, running
olddefconfig or building arm64 defconfig drops the unrecognized symbol and
disables the core, backend, and all dependent sub-drivers (gpio, reset,
hwmon, power supply, and rtc).
Should arch/arm64/configs/defconfig be updated and/or should the rtkit
backend select the core option and default to m or y when the Apple platform
dependencies are enabled?
[ ... ]
> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> new file mode 100644
> index 0000000000000..b8905c834c448
> --- /dev/null
> +++ b/drivers/mfd/macsmc-core.c
> @@ -0,0 +1,164 @@
[ ... ]
> +int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
> + void *cookie, struct blocking_notifier_head *event_handlers, bool is_acpi)
> +{
> + struct apple_smc *smc;
> + __be32 count;
> + int ret;
> +
> + smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
> + if (!smc)
> + return -ENOMEM;
> +
> + smc->dev = dev;
> + smc->be_cookie = cookie;
> + smc->be = ops;
> + smc->is_acpi = is_acpi;
> + smc->event_handlers = event_handlers;
> + mutex_init(&smc->mutex);
> + spin_lock_init(&smc->lock);
> +
> + ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
> + if (ret < 0)
> + return ret;
> + smc->key_count = be32_to_cpu(count);
[Severity: Low]
Doesn't passing &count (declared as __be32) to apple_smc_read_u32() trigger
a sparse endianness warning?
In include/linux/mfd/macsmc.h, apple_smc_read_u32() expects a host-endian
u32 * pointer:
static inline int apple_smc_read_u32(struct apple_smc *smc, smc_key key, u32 *p)
{
int ret = apple_smc_read(smc, key, p, sizeof(*p));
return (ret < 0) ? ret : ((ret != sizeof(*p)) ? -EINVAL : 0);
}
Previously, apple_smc_probe() called apple_smc_read() directly with &count,
which took a void * buffer. Should apple_smc_probe() either call
apple_smc_read() as before or use a helper that accepts __be32?
[ ... ]
> diff --git a/drivers/mfd/macsmc.c b/drivers/soc/apple/macsmc-rtkit.c
> similarity index 70%
> rename from drivers/mfd/macsmc.c
> rename to drivers/soc/apple/macsmc-rtkit.c
> index 514cba7dc897a..eaebeb1be3734 100644
> --- a/drivers/mfd/macsmc.c
> +++ b/drivers/soc/apple/macsmc-rtkit.c
[ ... ]
> @@ -458,49 +450,32 @@ static int apple_smc_probe(struct platform_device *pdev)
> return -EIO;
> }
>
> - dev_set_drvdata(&pdev->dev, smc);
> BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
>
> - ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
> - if (ret >= 0 && ret != sizeof(count))
> - ret = -EINVAL;
> - if (ret < 0)
> - return dev_err_probe(smc->dev, ret, "Failed to get key count");
> - smc->key_count = be32_to_cpu(count);
> -
> /* Enable notifications */
> - apple_smc_write_flag(smc, SMC_KEY(NTAP), true);
> - ret = devm_add_action_or_reset(dev, apple_smc_disable_notifications, smc);
> - if (ret)
> - return ret;
> + apple_smc_rtkit_rw_locked(smc, SMC_KEY(NTAP), &flag, sizeof(flag), NULL, 0);
>
> - ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE,
> - apple_smc_devs, ARRAY_SIZE(apple_smc_devs),
> - NULL, 0, NULL);
> - if (ret)
> - return dev_err_probe(smc->dev, ret, "Failed to register sub-devices");
> -
> -
> - return 0;
> + return apple_smc_probe(dev, &apple_smc_rtkit_backend_ops, smc,
> + &smc->event_handlers, false);
> }
[Severity: Medium]
If apple_smc_probe() fails before registering the
apple_smc_disable_notifications() cleanup action, won't SMC notifications
remain enabled on the error path?
In apple_smc_rtkit_probe(), notifications are enabled before calling
apple_smc_probe(). Inside apple_smc_probe() in drivers/mfd/macsmc-core.c,
several operations can fail and return early before
devm_add_action_or_reset() is called:
smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
if (!smc)
return -ENOMEM;
...
ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
if (ret < 0)
return ret;
smc->key_count = be32_to_cpu(count);
ret = apple_smc_get_key_by_index(smc, 0, &smc->first_key);
if (ret < 0)
return ret;
ret = apple_smc_get_key_by_index(smc, smc->key_count - 1, &smc->last_key);
if (ret < 0)
return ret;
dev_set_drvdata(dev, smc);
ret = devm_add_action_or_reset(dev, apple_smc_disable_notifications, smc);
Previously, notifications were only enabled after reading the key count and
the devm cleanup action was registered immediately afterward. In addition,
apple_smc_disable_notifications(), apple_smc_enter_atomic(),
apple_smc_write_atomic(), and apple_smc_rw() in drivers/mfd/macsmc-core.c
unconditionally call backend ops without checking if the callback pointer is
null.
Could notification enabling and its devm cleanup action be kept together
(or guarded for backends that do not implement all callbacks)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261029085504.3547-1-atharvatiwarilinuxdev@gmail.com?part=1
next prev parent reply other threads:[~2026-10-29 9:20 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 8:51 [RFC PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
2026-10-29 8:51 ` [RFC PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
2026-10-29 9:20 ` sashiko-bot [this message]
2026-10-29 8:51 ` [RFC PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
2026-10-29 9:23 ` sashiko-bot
2026-10-29 12:59 ` Ilpo Järvinen
2026-10-29 8:52 ` [RFC PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
2026-10-29 9:17 ` sashiko-bot
2026-10-29 13:30 ` Andy Shevchenko
2026-10-29 8:52 ` [RFC PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
2026-10-29 9:17 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
2026-10-29 9:20 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
2026-10-29 9:16 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
2026-10-29 9:15 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-10-29 9:11 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
2026-10-29 9:16 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
2026-10-29 9:19 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
2026-10-29 9:13 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
2026-10-29 9:18 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
2026-10-29 9:20 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
2026-10-29 9:22 ` Sasha Finkelstein
2026-10-29 14:39 ` Atharva Tiwari
2026-10-29 14:53 ` Sasha Finkelstein
2026-10-29 9:26 ` 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=sashiko-outbox-189026@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=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.