From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796392587; b=o/lCqbhG+ris+zZnrg98CqhEJ3/jOxP+B6vXcyd3lCIKw6OVXRRsBGzBvQamSJh6slsJ NM7FDbXWeTxJYoJjpeGrfK5AKR+gRyVy9bE/5AvSJVShgylOteK+wsihV76WQ6g2uqare VGYc5OPRKYo4N0OIjj+T79sTCC09L2dqON1TswP+8qCf3LJ29fF0UN0ki+IZ+ka5pM0QK ilpdWTFFWhtQEj1n74Ktze1y/3QlnXgc0DT25dNdqE+rd7fXyToSRis1tn+QhYsD7VjbD 1ZZTV/0jE0zc4Ife6TwqsXK/rNbvIAWmTESfPdV03ReTJP/2heE79hZsuTAUygH3/vg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796392587; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=D4+65Mz/osrZBk4mlbxbnJZOpvNvnIuWgv/del3Pm5o=; b=utGZnIN15dGs/p3Vh3dcaNafWIfrYJ4jlLfnjXj5WS7IDH/LdwqcbUSBpabZCzHWYyjx HzkaxwHRWW/YiRy8KZnAyzzns0ZWrwq1swPHQx+2rYUthauDH+nEhtsG90Lnb4GdiTRTK i7g3kcXPUI2s8Mjk1AGTRAp8rJmU3HJTMnPRLw5xLqa6y1O+ECr9VKng25HBqCdJY5BHl UfWVuzCqq2HEaa7is3eOtu4qP2MU/Id+yq9y1C5ildFcYpdp5eCeMEvSbqSsv7uFkeCN8 Crh1YTbuD9tuWWIM0irYLVbey52P84O8ncMlsjtnIm/khsuu2c7NMUL5vlcjcwbrLJg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Qm26xBye; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BEBF606A322; Fri, 4 Dec 2026 13:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Qm26xBye Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF06B1F000C2; Fri, 4 Dec 2026 13:56:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796392587; bh=D4+65Mz/osrZBk4mlbxbnJZOpvNvnIuWgv/del3Pm5o=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Qm26xByeADRxU/XFEA10xtt0DoqcZLynp6sD+ZgcLy3nrEq9Y1cHS2+ApBww3bKYv 5xL8Sw7Dhmcl+4CxxQoLREs90AlU6qi055cWOFv39awhZY2OJQmY1o8snLXJJ4wvIc 7Cs0SQIt/QDVI+6ZQ1/OEUKEtru1BjJqzFRUotn+fqLbwDditLFsrY0c3FtyvcGF4o Jo3qRgqB8UCEIrcCNDcMMEsTleCDyLhCRdEmszs4ZOQ9vwgAyszMGT/Nwsk46/O975 beDZBYG7z4xvLG8vqQs0Hura48kzLSLH2vT1VtuzJd11+sXgEZ4WuXz1WL1jYHumlu k4bNuIZSOdNfA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 01/14] treewide: Add backend for macsmc Reply-To: sashiko-reviews@lists.linux.dev To: "Atharva Tiwari" Cc: "Ihor Odainyi" , "Antoine Sidem" , "Aditya Garg" , "Bjorn Helgaas" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H. Peter Anvin" , "Rafael J. Wysocki" , "Len Brown" , "Linus Walleij" , "Bartosz Golaszewski" , "Sven Peter" , "Janne Grunau" , "Neal Gompa" , "Guenter Roeck" , "Jonathan Cameron" , "David Lechner" , =?utf-8?b?TnVubyBTw6E=?= , "Andy Shevchenko" , "Lee Jones" , "Pavel Machek" , "Griffin Kroah-Hartman" , "Hans de Goede" , =?utf-8?b?SWxwbyBKw6RydmluZW4=?= , "Sebastian Reichel" , "Alexandre Belloni" , "Wim Van Sebroeck" , "Jarkko Sakkinen" , "Mimi Zohar" , "Roberto Sassu" , "Dmitry Kasatkin" , "Eric Snowberg" , "Paul Moore" , "James Morris" , "Serge E. Hallyn" , 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 In-Reply-To: <20261204131619.5059-2-atharvatiwarilinuxdev@gmail.com> References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> <20261204131619.5059-2-atharvatiwarilinuxdev@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 13:56:24 +0000 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 > Tested-by: Antoine Sidem > Tested-by: Aditya Garg > Signed-off-by: Atharva Tiwari [Severity: Low] The MFD convention for commit subjects is "mfd: macsmc: " 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. > =20 > -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=3Dm 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 voi= d *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, s= ize_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 =3D smc->be->get_key_by_index(smc->be_cookie, index, key); > + *key =3D 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_o= ps *ops, > + void *cookie, struct blocking_notifier_head *event_handlers, bool is_a= cpi) > +{ > + struct apple_smc *smc; > + __be32 count; > + int ret; [ ... ] > + ret =3D apple_smc_read_u32(smc, SMC_KEY(#KEY), &count); > + if (ret < 0) > + return ret; > + smc->key_count =3D 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 =3D 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 =3D 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 =3D 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; > } > =20 > - dev_set_drvdata(&pdev->dev, smc); > BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers); > =20 > - ret =3D apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count)); > - if (ret >=3D 0 && ret !=3D sizeof(count)) > - ret =3D -EINVAL; > - if (ret < 0) > - return dev_err_probe(smc->dev, ret, "Failed to get key count"); > - smc->key_count =3D be32_to_cpu(count); > - > /* Enable notifications */ > - apple_smc_write_flag(smc, SMC_KEY(NTAP), true); > - ret =3D 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); > =20 > - ret =3D 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) > =20 > +#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 even though all RTKit fields were removed from struct apple_smc, pulling RTKit, mailbox, and OF headers into generic and x86 consumers. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204131619.5059= -1-atharvatiwarilinuxdev@gmail.com?part=3D1