Linux Hardware Monitor development
 help / color / mirror / Atom feed
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 06/14] leds: add support for macsmc kbl
Date: Thu, 29 Oct 2026 09:16:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-189015@kernel.org> (raw)
In-Reply-To: <20261029085504.3547-7-atharvatiwarilinuxdev@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] leds: macsmc: sleeping SMC write registered as non-blocking brightness_set
- [Medium] leds: macsmc: non-standard LED name breaks kbd_backlight discovery
- [Medium] leds: macsmc: missing suspend/resume handling loses backlight state
- [Low] leds: macsmc: commit prefix, drv naming, and Makefile sort order violations
--

commit 62f13fe6413b6947c13026e13a39c022cd83dde2
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

leds: add support for macsmc kbl

This commit adds a LED class driver for the Apple SMC keyboard backlight on
Intel Macs and registers the macsmc-led MFD cell when the LKSB key is present,
intended to replace the keyboard backlight support in applesmc.

>     leds: add support for macsmc kbl
>     
>     Add a LED class driver to control the keyboard backlight.
>     
>     This replaces the keyboard backlight support in applesmc.
>     
>     Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

[Severity: Low]
This isn't a bug, but should the commit subject follow the LED subsystem
convention of including the driver prefix and capitalizing the description,
such as "leds: macsmc: Add support for keyboard backlight"?

[ ... ]

> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 4d4b089156e24..7c38dbef42390 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -12,6 +12,7 @@ obj-$(CONFIG_LEDS_KUNIT_TEST)		+= led-test.o
>  obj-$(CONFIG_LEDS_88PM860X)		+= leds-88pm860x.o
>  obj-$(CONFIG_LEDS_ACER_A500)		+= leds-acer-a500.o
>  obj-$(CONFIG_LEDS_ADP5520)		+= leds-adp5520.o
> +obj-$(CONFIG_LEDS_MACSMC)		+= leds-macsmc.o
>  obj-$(CONFIG_LEDS_AN30259A)		+= leds-an30259a.o

[Severity: Low]
This isn't a bug, but the platform drivers section in drivers/leds/Makefile
is kept sorted alphabetically. Should leds-macsmc.o be placed in alphabetical
order right before leds-max5970.o?

> diff --git a/drivers/leds/leds-macsmc.c b/drivers/leds/leds-macsmc.c
> new file mode 100644
> index 0000000000000..f38ef2113aced
> --- /dev/null
> +++ b/drivers/leds/leds-macsmc.c

[ ... ]

> +static enum led_brightness macsmc_led_get_brightness(struct led_classdev *cdev)
> +{
> +	struct macsmc_led *drv = container_of(cdev, struct macsmc_led, cdev);
> +
> +	return drv->brightness;
> +}
> +
> +static void macsmc_led_set_brightness(struct led_classdev *cdev, enum led_brightness value)
> +{
> +	struct macsmc_led *drv = container_of(cdev, struct macsmc_led, cdev);
> +
> +	drv->brightness = (u8) value;
> +
> +	apple_smc_write_u16(drv->smc, SMC_KEY(LKSB), drv->brightness);
> +}
> +
> +static int macsmc_led_probe(struct platform_device *pdev)
> +{
> +	struct macsmc_led *drv;

[Severity: Low]
This isn't a bug, but could the private data pointer be named ddata instead
of drv in macsmc_led_get_brightness(), macsmc_led_set_brightness(), and
macsmc_led_probe() to match the LED subsystem naming convention?

> +
> +	drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
> +	if (!drv)
> +		return -ENOMEM;
> +
> +	drv->smc = dev_get_drvdata(pdev->dev.parent);
> +
> +	drv->cdev.name = "macsmc-led";

[Severity: Medium]
Will setting drv->cdev.name to "macsmc-led" in macsmc_led_probe() cause a
regression for userspace tools discovering the keyboard backlight?

In drivers/hwmon/applesmc.c, which this driver replaces, the LED class device
is registered with the name "smc::kbd_backlight":

    static struct led_classdev applesmc_backlight = {
        .name            = "smc::kbd_backlight",
        .default_trigger = "nand-disk",
        .brightness_set  = applesmc_brightness_set,
    };

Documentation/leds/leds-class.rst also specifies that keyboard backlight LED
devices should use kbd_backlight as the function suffix so that userspace
consumers (such as upower and systemd-backlight) can identify them under
/sys/class/leds/. Should this keep "smc::kbd_backlight" to preserve UAPI
compatibility?

> +	drv->cdev.max_brightness = 255;
> +	drv->cdev.brightness_get = macsmc_led_get_brightness;
> +	drv->cdev.brightness_set = macsmc_led_set_brightness;

[Severity: High]
Can registering macsmc_led_set_brightness() on drv->cdev.brightness_set in
macsmc_led_probe() sleep in atomic context when an atomic LED trigger or
software blink timer fires?

When software blinking or an atomic trigger updates the LED, the call chain
led_timer_function() or led_trigger_event() -> led_set_brightness_nosleep() ->
led_set_brightness_nopm() -> __led_set_brightness() invokes the
brightness_set callback synchronously without deferring to
set_brightness_work:

    /* Use brightness_set op if available, it is guaranteed not to sleep */
    if (!__led_set_brightness(led_cdev, value))
        return;

However, macsmc_led_set_brightness() calls apple_smc_write_u16() ->
apple_smc_write():

    int apple_smc_write(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
    {
        guard(mutex)(&smc->mutex);
        return smc->be->write(smc->be_cookie, key, buf, size);
    }

This acquires a sleeping mutex and calls apple_smc_acpi_write(), which sleeps
via wait_for_completion_timeout() and fsleep(). Unlike applesmc, which queued
a work item on a workqueue in applesmc_brightness_set(), this sleeps directly
in the caller's context and also discards any error returned by
apple_smc_write_u16().

Should macsmc_led_set_brightness() be registered via
drv->cdev.brightness_set_blocking instead, and return the result of
apple_smc_write_u16()?

> +	drv->cdev.dev = &pdev->dev;
> +
> +	return devm_led_classdev_register(&pdev->dev, &drv->cdev);
> +}

[Severity: Medium]
Does omitting suspend and resume handling here cause the keyboard backlight
state to be lost across system suspend or hibernation?

In drivers/hwmon/applesmc.c, applesmc_pm_resume() and applesmc_pm_restore()
restore the saved brightness to the hardware key on resume:

    static int applesmc_pm_resume(struct device *dev)
    {
        if (smcreg.has_key_backlight)
            applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2);
        return 0;
    }

Because macsmc_led_probe() does not set LED_CORE_SUSPENDRESUME in
drv->cdev.flags (and macsmc_led_driver does not define PM callbacks), the
keyboard backlight is not turned off on suspend or restored on resume. Note
 also that if LED_CORE_SUSPENDRESUME is enabled, the custom brightness_get
callback returning drv->brightness would return 0 during resume after
led_classdev_suspend() sets the brightness to 0, unless the LED core's
cached brightness is used instead of a custom brightness_get callback.

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

  reply	other threads:[~2026-10-29  9:16 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
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 [this message]
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-189015@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox