From: Armin Wolf <W_Armin@gmx.de>
To: Rong Zhang <i@rong.moe>, lee@kernel.org, pavel@kernel.org
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 09/10] leds: Support custom sysfs groups on multicolor and flash LEDs
Date: Tue, 20 Oct 2026 22:57:32 +0200 [thread overview]
Message-ID: <96bc0a90-2713-407b-960e-10f9485aecf9@gmx.de> (raw)
In-Reply-To: <e6e327c35bc579d9063f2514abab7e59d4d9ed15.camel@rong.moe>
Am 19.10.26 um 13:53 schrieb Rong Zhang:
> Hi Armin,
>
> Nice refactor!
>
> On Sun, 2026-10-18 at 15:46 +0200, Armin Wolf wrote:
>> Drivers registering multicolor/flash LEDs currently cannot use
>> led_cdev->groups due to said field being overwritten by the
>> multicolor/flash LED registration functions. Fix this by assigning
>> each LED type a seperate device type ("multicolor" and "flash")
>> that carries the sysfs attributes instead.
>>
>> Also assign a device type for standard LEDs ("standard") for symmetry.
>>
>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>> ---
>> drivers/leds/led-class-flash.c | 108 ++++++++++++++--------------
>> drivers/leds/led-class-multicolor.c | 18 ++++-
>> drivers/leds/led-class.c | 5 ++
>> include/linux/led-class-flash.h | 5 --
>> 4 files changed, 73 insertions(+), 63 deletions(-)
>>
>> diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c
>> index 953265fddb7d..e023511cea1c 100644
>> --- a/drivers/leds/led-class-flash.c
>> +++ b/drivers/leds/led-class-flash.c
>> @@ -13,6 +13,7 @@
>> #include <linux/module.h>
>> #include <linux/slab.h>
>> #include <linux/sysfs.h>
>> +#include "leds.h"
>>
>> #define has_flash_op(fled_cdev, op) \
>> (fled_cdev && fled_cdev->ops->op)
>> @@ -207,42 +208,56 @@ static ssize_t flash_fault_show(struct device *dev, const struct device_attribut
>> }
>> static const DEVICE_ATTR_RO(flash_fault);
>>
>> -static const struct attribute *const led_flash_strobe_attrs[] = {
>> +static const struct attribute *const led_flash_attrs[] = {
>> &dev_attr_flash_strobe.attr,
>> - NULL,
>> -};
>> -
>> -static const struct attribute *const led_flash_timeout_attrs[] = {
>> &dev_attr_flash_timeout.attr,
>> &dev_attr_max_flash_timeout.attr,
>> - NULL,
>> -};
>> -
>> -static const struct attribute *const led_flash_brightness_attrs[] = {
>> &dev_attr_flash_brightness.attr,
>> &dev_attr_max_flash_brightness.attr,
>> - NULL,
>> -};
>> -
>> -static const struct attribute *const led_flash_fault_attrs[] = {
>> &dev_attr_flash_fault.attr,
>> NULL,
>> };
>>
>> -static const struct attribute_group led_flash_strobe_group = {
>> - .attrs_const = led_flash_strobe_attrs,
>> -};
>> +static umode_t led_flash_is_visible(struct kobject *kobj, const struct attribute *attr, int n)
>> +{
>> + struct device *dev = kobj_to_dev(kobj);
>> + struct led_classdev *led_cdev = dev_get_drvdata(dev);
>> + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev);
>> +
>> + if (attr == &dev_attr_flash_strobe.attr)
>> + return attr->mode;
>> +
>> + if (attr == &dev_attr_flash_timeout.attr && fled_cdev->ops->timeout_set)
>> + return attr->mode;
>>
>> -static const struct attribute_group led_flash_timeout_group = {
>> - .attrs_const = led_flash_timeout_attrs,
>> + if (attr == &dev_attr_max_flash_timeout.attr && fled_cdev->ops->timeout_set)
>> + return attr->mode;
>> +
>> + if (attr == &dev_attr_flash_brightness.attr && fled_cdev->ops->flash_brightness_set)
>> + return attr->mode;
>> +
>> + if (attr == &dev_attr_max_flash_brightness.attr && fled_cdev->ops->flash_brightness_set)
>> + return attr->mode;
>> +
>> + if (attr == &dev_attr_flash_fault.attr && fled_cdev->ops->fault_get)
>> + return attr->mode;
>> +
>> + return 0;
>> +}
>> +
>> +static const struct attribute_group led_flash_group = {
>> + .is_visible_const = led_flash_is_visible,
>> + .attrs_const = led_flash_attrs,
>> };
>>
>> -static const struct attribute_group led_flash_brightness_group = {
>> - .attrs_const = led_flash_brightness_attrs,
>> +static const struct attribute_group *led_flash_groups[] = {
>> + &led_flash_group,
>> + NULL,
>> };
>>
>> -static const struct attribute_group led_flash_fault_group = {
>> - .attrs_const = led_flash_fault_attrs,
> Hmm, a bunch of back-and-forth changes. I suppose the is_visible_const
> changes can be merged into PATCH 3, right?
>
> Thanks,
> Rong
If the LED subsystem maintainers are OK with this then i can gladly introduce
the is_visible_const callback already in patch 3.
Thanks,
Armin Wolf
>> +static const struct device_type led_flash_device_type = {
>> + .name = "flash",
>> + .groups = led_flash_groups,
>> };
>>
>> static void led_flash_resume(struct led_classdev *led_cdev)
>> @@ -254,28 +269,6 @@ static void led_flash_resume(struct led_classdev *led_cdev)
>> call_flash_op(fled_cdev, timeout_set, fled_cdev->timeout.val);
>> }
>>
>> -static void led_flash_init_sysfs_groups(struct led_classdev_flash *fled_cdev)
>> -{
>> - struct led_classdev *led_cdev = &fled_cdev->led_cdev;
>> - const struct led_flash_ops *ops = fled_cdev->ops;
>> - const struct attribute_group **flash_groups = fled_cdev->sysfs_groups;
>> -
>> - int num_sysfs_groups = 0;
>> -
>> - flash_groups[num_sysfs_groups++] = &led_flash_strobe_group;
>> -
>> - if (ops->flash_brightness_set)
>> - flash_groups[num_sysfs_groups++] = &led_flash_brightness_group;
>> -
>> - if (ops->timeout_set)
>> - flash_groups[num_sysfs_groups++] = &led_flash_timeout_group;
>> -
>> - if (ops->fault_get)
>> - flash_groups[num_sysfs_groups++] = &led_flash_fault_group;
>> -
>> - led_cdev->groups = flash_groups;
>> -}
>> -
>> int led_classdev_flash_register_ext(struct device *parent,
>> struct led_classdev_flash *fled_cdev,
>> struct led_init_data *init_data)
>> @@ -289,26 +282,29 @@ int led_classdev_flash_register_ext(struct device *parent,
>>
>> led_cdev = &fled_cdev->led_cdev;
>>
>> - if (led_cdev->flags & LED_DEV_CAP_FLASH) {
>> - if (!led_cdev->brightness_set_blocking)
>> - return -EINVAL;
>> + if (!(led_cdev->flags & LED_DEV_CAP_FLASH))
>> + return led_classdev_register_ext(parent, led_cdev, init_data);
>>
>> - ops = fled_cdev->ops;
>> - if (!ops || !ops->strobe_set)
>> - return -EINVAL;
>> + if (!led_cdev->brightness_set_blocking)
>> + return -EINVAL;
>>
>> - led_cdev->flash_resume = led_flash_resume;
>> + ops = fled_cdev->ops;
>> + if (!ops || !ops->strobe_set)
>> + return -EINVAL;
>>
>> - /* Select the sysfs attributes to be created for the device */
>> - led_flash_init_sysfs_groups(fled_cdev);
>> - }
>> + led_cdev->flash_resume = led_flash_resume;
>>
>> /* Register led class device */
>> - ret = led_classdev_register_ext(parent, led_cdev, init_data);
>> + ret = led_classdev_init(parent, led_cdev, init_data);
>> if (ret < 0)
>> return ret;
>>
>> - return 0;
>> + led_cdev->dev->type = &led_flash_device_type;
>> + ret = led_classdev_add(led_cdev);
>> + if (ret < 0)
>> + put_device(led_cdev->dev);
>> +
>> + return ret;
>> }
>> EXPORT_SYMBOL_GPL(led_classdev_flash_register_ext);
>>
>> diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c
>> index 57df0b2e785b..9b8c37f7bdf4 100644
>> --- a/drivers/leds/led-class-multicolor.c
>> +++ b/drivers/leds/led-class-multicolor.c
>> @@ -12,6 +12,7 @@
>> #include <linux/slab.h>
>> #include <linux/sysfs.h>
>> #include <linux/uaccess.h>
>> +#include "leds.h"
>>
>> static unsigned int led_mc_get_max_intensity(struct led_classdev_mc *mcled_cdev, size_t index)
>> {
>> @@ -159,11 +160,17 @@ static const struct attribute *const led_multicolor_attrs[] = {
>> };
>> ATTRIBUTE_GROUPS(led_multicolor);
>>
>> +static const struct device_type led_multicolor_device_type = {
>> + .name = "multicolor",
>> + .groups = led_multicolor_groups,
>> +};
>> +
>> int led_classdev_multicolor_register_ext(struct device *parent,
>> struct led_classdev_mc *mcled_cdev,
>> struct led_init_data *init_data)
>> {
>> struct led_classdev *led_cdev;
>> + int ret;
>>
>> if (!mcled_cdev)
>> return -EINVAL;
>> @@ -176,9 +183,16 @@ int led_classdev_multicolor_register_ext(struct device *parent,
>>
>> led_cdev = &mcled_cdev->led_cdev;
>> led_cdev->flags |= LED_MULTI_COLOR;
>> - mcled_cdev->led_cdev.groups = led_multicolor_groups;
>> + ret = led_classdev_init(parent, led_cdev, init_data);
>> + if (ret < 0)
>> + return ret;
>> +
>> + led_cdev->dev->type = &led_multicolor_device_type;
>> + ret = led_classdev_add(led_cdev);
>> + if (ret < 0)
>> + put_device(led_cdev->dev);
>>
>> - return led_classdev_register_ext(parent, led_cdev, init_data);
>> + return ret;
>> }
>> EXPORT_SYMBOL_GPL(led_classdev_multicolor_register_ext);
>>
>> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
>> index ace417a2388e..49b321b3d863 100644
>> --- a/drivers/leds/led-class.c
>> +++ b/drivers/leds/led-class.c
>> @@ -613,6 +613,10 @@ int led_classdev_add(struct led_classdev *led_cdev)
>> }
>> EXPORT_SYMBOL_GPL(led_classdev_add);
>>
>> +static const struct device_type led_device_type = {
>> + .name = "standard",
>> +};
>> +
>> /**
>> * led_classdev_register_ext - register a new object of led_classdev class
>> * with init data.
>> @@ -631,6 +635,7 @@ int led_classdev_register_ext(struct device *parent,
>> if (ret < 0)
>> return ret;
>>
>> + led_cdev->dev->type = &led_device_type;
>> ret = led_classdev_add(led_cdev);
>> if (ret < 0)
>> put_device(led_cdev->dev);
>> diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h
>> index 775a96217518..5204ef60dc4b 100644
>> --- a/include/linux/led-class-flash.h
>> +++ b/include/linux/led-class-flash.h
>> @@ -28,8 +28,6 @@ struct led_classdev_flash;
>> #define LED_FAULT_LED_OVER_TEMPERATURE (1 << 8)
>> #define LED_NUM_FLASH_FAULTS 9
>>
>> -#define LED_FLASH_SYSFS_GROUPS_SIZE 5
>> -
>> struct led_flash_ops {
>> /* set flash brightness */
>> int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
>> @@ -79,9 +77,6 @@ struct led_classdev_flash {
>>
>> /* flash timeout value in microseconds along with its constraints */
>> struct led_flash_setting duration;
>> -
>> - /* LED Flash class sysfs groups */
>> - const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE];
>> };
>>
>> static inline struct led_classdev_flash *lcdev_to_flcdev(
next prev parent reply other threads:[~2026-10-20 20:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 13:46 [PATCH 00/10] leds: class: " Armin Wolf
2026-10-18 13:46 ` [PATCH 01/10] leds: class: Constify sysfs attributes Armin Wolf
2026-10-18 13:46 ` [PATCH 02/10] leds: multicolor: " Armin Wolf
2026-10-18 13:46 ` [PATCH 03/10] leds: flash: " Armin Wolf
2026-10-18 13:46 ` [PATCH 04/10] leds: class: Create "brightness_hw_changed" attribute atomically Armin Wolf
2026-10-19 11:51 ` Rong Zhang
2026-10-20 20:55 ` Armin Wolf
2026-10-18 13:46 ` [PATCH 05/10] leds: class: Fix race condition when creating the device Armin Wolf
2026-10-18 13:46 ` [PATCH 06/10] leds: class: Take the LED access lock when reading brightness_hw_changed Armin Wolf
2026-10-18 13:46 ` [PATCH 07/10] leds: class: Use correct type for brightness_hw_changed field Armin Wolf
2026-10-18 13:46 ` [PATCH 08/10] leds: class: Split led_classdev_register_ext() Armin Wolf
2026-10-18 13:46 ` [PATCH 09/10] leds: Support custom sysfs groups on multicolor and flash LEDs Armin Wolf
2026-10-19 11:53 ` Rong Zhang
2026-10-20 20:57 ` Armin Wolf [this message]
2026-10-18 13:46 ` [PATCH 10/10] leds: multicolor: Adjust maximum subled intensity during initialization Armin Wolf
2026-10-19 11:54 ` Rong Zhang
2026-10-20 20:59 ` Armin Wolf
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=96bc0a90-2713-407b-960e-10f9485aecf9@gmx.de \
--to=w_armin@gmx.de \
--cc=i@rong.moe \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
/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
all inboxes | Powered by JetHome®