Linux PCI subsystem development
 help / color / mirror / Atom feed
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>,
	"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 01/14] treewide: Add backend for macsmc
Date: Fri, 04 Dec 2026 13:56:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-249906@kernel.org> (raw)
In-Reply-To: <20261204131619.5059-2-atharvatiwarilinuxdev@gmail.com>

Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] mfd: macsmc: Kconfig split disables Apple SMC drivers in arm64
  defconfig
- [Medium] mfd: macsmc: notifications left enabled if apple_smc_probe()
  fails early
- [Low] mfd: macsmc: endianness type mismatch in apple_smc_probe()
- [Low] mfd: macsmc: signed %d format specifier used for u32 key_count
- [Low] mfd: macsmc: non-standard subject prefix and incomplete commit
  message
- [Low] mfd: macsmc-core: apple_smc_probe() passes raw -1 to
  devm_mfd_add_devices()
- [Low] mfd: macsmc: undocumented swab32() in core
  apple_smc_get_key_by_index()
- [Low] mfd: macsmc: missing NULL checks on optional ops and backend
  locking docs
- [Low] mfd: macsmc.h retains unused RTKit header include and RTKit-only
  definitions
--

commit 97275525c07f52eb987554687e4771a43c630a9d
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

> treewide: Add backend for macsmc
>
> Split the Apple SMC driver into a common core and a backend
> that handles the actual communication. The existing RTKit
> code moves to its own backend, and nothing changes for
> Apple Silicon.
>
> This lets the same SMC drivers run on other kinds of
> hardware, starting with Intel Macs, as a replacement for
> applesmc.
>
> Tested-by: Ihor Odainyi <pv4k@odayny.com>
> Tested-by: Antoine Sidem <sidemantoine@gmail.com>
> Tested-by: Aditya Garg <aditya.garg@linux.dev>
> Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

[Severity: Low]
The MFD convention for commit subjects is "mfd: macsmc: <Capitalized
description>" rather than "treewide:".  The changelog also states that
nothing changes for Apple Silicon, omitting the Kconfig rename, dropping
the OF dependency from SENSORS_MACSMC_HWMON, renaming the RTKit platform
driver from macsmc to macsmc-rtkit, caching first_key and last_key in
apple_smc_probe(), and adding the ACPI MFD cells and SMC_INT_* macros.

[ ... ]

> 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 deleting CONFIG_MFD_MACSMC silently disable the Apple Silicon SMC
driver stack in arm64 defconfig and existing configs?

arch/arm64/configs/defconfig still sets CONFIG_MFD_MACSMC=m and is not
updated in this series, so make defconfig and olddefconfig drop the SMC
core, RTKit backend, GPIO, reboot/power-off, hwmon, and RTC drivers on
Apple Silicon.

Making MFD_MACSMC_CORE a hidden symbol selected by MACSMC_RTKIT and
updating arm64 defconfig would avoid breaking existing builds.  Renaming
the RTKit platform driver from macsmc to macsmc-rtkit also changes the
sysfs driver path and module name on Apple Silicon.

[ ... ]

> 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

[ ... ]

> +int apple_smc_enter_atomic(struct apple_smc *smc)
> +{
> +	guard(mutex)(&smc->mutex);
> +	return smc->be->enter_atomic(smc->be_cookie);
> +}
> +EXPORT_SYMBOL(apple_smc_enter_atomic);
> +
> +int apple_smc_write_atomic(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
> +{
> +	guard(spinlock_irqsave)(&smc->lock);
> +	return smc->be->write_atomic(smc->be_cookie, key, buf, size);
> +}
> +EXPORT_SYMBOL(apple_smc_write_atomic);
> +
> +int apple_smc_rw(struct apple_smc *smc, smc_key key, const void *wbuf, size_t wsize,
> +		void *rbuf, size_t rsize)
> +{
> +	guard(mutex)(&smc->mutex);
> +	return smc->be->rw(smc->be_cookie, key, wbuf, wsize, rbuf, rsize);
> +}
> +EXPORT_SYMBOL(apple_smc_rw);

[Severity: Low]
Should these wrappers check for NULL before invoking enter_atomic,
write_atomic, and rw, and return -EOPNOTSUPP when unimplemented?

Commit "platform/x86: add backend for macsmc in intel macs" leaves those
three callbacks NULL in apple_smc_acpi_be_ops, so calling them on an
ACPI backend would cause a NULL pointer dereference.

The kernel-doc for struct apple_smc_backend_ops in
include/linux/mfd/macsmc.h could also document which callbacks are
optional and their locking context (smc->mutex for sleeping ops vs
smc->lock with spin_lock_irqsave for write_atomic).

> +
> +int apple_smc_get_key_by_index(struct apple_smc *smc, int index, smc_key *key)
> +{
> +	guard(mutex)(&smc->mutex);
> +	int ret;
> +
> +	ret = smc->be->get_key_by_index(smc->be_cookie, index, key);
> +	*key = swab32(*key);
> +
> +	return ret;
> +}

[Severity: Low]
Should the byte swap in apple_smc_get_key_by_index() live in the
backends rather than the generic core?

Every other callback in struct apple_smc_backend_ops uses host-order
smc_key values, and get_key_by_index does not document that it must
return a byte-swapped key.  Moving the conversion into each backend
would keep the interface consistent with typedef smc_key.

[ ... ]

> +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;

[ ... ]

> +	ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
> +	if (ret < 0)
> +		return ret;
> +	smc->key_count = be32_to_cpu(count);

[Severity: Low]
Does passing __be32 *count to apple_smc_read_u32() reintroduce a Sparse
-Wbitwise warning?

apple_smc_read_u32() takes a host-endian u32 *, which regresses
0a29aa605286 ("mfd: macsmc: Fix key count endianness annotation").
Reading into count with apple_smc_read() and checking the returned byte
count avoids the type mismatch.

[ ... ]

> +	if (smc->is_acpi) {
> +		ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_common,
> +			ARRAY_SIZE(apple_smc_acpi_common), NULL, 0, NULL);
> +		if (ret < 0)
> +			return ret;
> +
> +		if (apple_smc_key_exists(smc, SMC_KEY(CLKO))) {
> +			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_rtc,
> +				ARRAY_SIZE(apple_smc_acpi_rtc), 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);
> +	if (ret < 0)
> +		return ret;

[Severity: Low]
These devm_mfd_add_devices() calls pass a raw -1 instead of
PLATFORM_DEVID_AUTO (preferred for new MFD code) or PLATFORM_DEVID_NONE,
which the driver used before this split.

> +
> +	dev_info(dev, "Successfully Initialized (%d keys First key: %p4ch Last key: %p4ch)\n",
> +			smc->key_count, &smc->first_key, &smc->last_key);

[Severity: Low]
smc->key_count is a u32, so %u would match its type better than %d.

[ ... ]

> 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]
Does enabling NTAP notifications here leave them enabled if
apple_smc_probe() fails early?

In apple_smc_probe(), devm_kzalloc() and the initial #KEY, first_key,
and last_key queries all run before devm_add_action_or_reset() registers
apple_smc_disable_notifications().  If any of those fail, probe unwinds
without disabling notifications in firmware.

Enabling notifications through a backend callback right before
devm_add_action_or_reset() in apple_smc_probe() (or registering the
cleanup action immediately here) would keep enable and disable balanced.

[ ... ]

> diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h
> index cc09ecce0df74..cdd040f0c010f 100644
> --- a/include/linux/mfd/macsmc.h
> +++ b/include/linux/mfd/macsmc.h
> @@ -47,6 +47,25 @@ typedef u32 smc_key;
>  #define APPLE_SMC_WRITABLE BIT(6)
>  #define APPLE_SMC_FUNCTION BIT(4)
>  
> +#define SMC_MSG_READ_KEY                0x10
> +#define SMC_MSG_WRITE_KEY               0x11
> +#define SMC_MSG_GET_KEY_BY_INDEX        0x12
> +#define SMC_MSG_GET_KEY_INFO            0x13
> +#define SMC_MSG_INITIALIZE              0x17
> +#define SMC_MSG_NOTIFICATION            0x18
> +#define SMC_MSG_RW_KEY                  0x20

[Severity: Low]
Can SMC_MSG_INITIALIZE, SMC_MSG_NOTIFICATION, SMC_MSG_RW_KEY, and
enum apple_smc_boot_stage stay private to drivers/soc/apple/macsmc-rtkit.c?

They are only used by the RTKit backend across the series.  This header
also still includes <linux/soc/apple/rtkit.h> even though all RTKit
fields were removed from struct apple_smc, pulling RTKit, mailbox, and
OF headers into generic and x86 consumers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=1

  reply	other threads:[~2026-12-04 13:56 UTC|newest]

Thread overview: 53+ 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 [this message]
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
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 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-249906@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=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