mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Armin Wolf <W_Armin@gmx.de>
To: Lee Jones <lee@kernel.org>
Cc: pavel@kernel.org, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org, i@rong.moe
Subject: Re: [PATCH v3 08/11] leds: class: Split led_classdev_register_ext()
Date: Sat, 28 Nov 2026 14:24:09 +0100	[thread overview]
Message-ID: <1bb5237d-17ba-4c5b-8f9a-15f06eb3c09b@gmx.de> (raw)
In-Reply-To: <179568576204.32537.4412828047245874349@kernel.org>

Am 27.11.26 um 15:42 schrieb Lee Jones:

> --- checkpatch.pl (4 issues) ---
> Line 149: ERROR: code indent should use tabs where possible
> Line 149: WARNING: please, no spaces at the start of a line
> Line 150: ERROR: code indent should use tabs where possible
> Line 150: WARNING: please, no spaces at the start of a line
> ----------------------------------
>
> ???

My bad, i forgot to reinstall my post-commit hook when cloning the kernel tree.

>> Split led_classdev_register_ext() into two separate internal functions
>> to prepare for future changes around LED class device initialization.
>>
>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>> ---
>>   drivers/leds/led-class.c | 102 ++++++++++++++++++++++++++++++++-------
>>   drivers/leds/leds.h      |   3 ++
>>   2 files changed, 87 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
>> index 8494a1ca0353..2f62141268ab 100644
>> --- a/drivers/leds/led-class.c
>> +++ b/drivers/leds/led-class.c
>> @@ -253,9 +253,15 @@ static struct led_classdev *led_module_get(struct device *led_dev)
>>   	return led_cdev;
>>   }
>>
>> +static void led_classdev_release(struct device *dev)
>> +{
>> +	kfree(dev);
>> +}
>> +
>>   static const struct class leds_class = {
>>   	.name = "leds",
>>   	.dev_groups = led_groups,
>> +	.dev_release = led_classdev_release,
>>   	.pm = &leds_class_dev_pm_ops,
>>   };
>>
>> @@ -490,16 +496,19 @@ static int led_classdev_next_name(const char *init_name, char *name,
>>   }
>>
>>   /**
>> - * led_classdev_register_ext - register a new object of led_classdev class
>> - *			       with init data.
>> - *
>> - * @parent: parent of LED device
>> + * led_classdev_init - Initialize a new LED class device.
>> + * @parent: parent of LED device.
>>    * @led_cdev: the led_classdev structure for this device.
>> - * @init_data: LED class device initialization data
>> + * @init_data: LED class device initialization data.
>> + *
>> + * Initializes a new LED class device, but does not register with the
>> + * subsystem yet. Useful for performing additional initialization before
>> + * adding the LED class device to the subsystem using led_classdev_add().
>> + *
>> + * Return: Zero on success or a negative error code on failure.
>>    */
>> -int led_classdev_register_ext(struct device *parent,
>> -			      struct led_classdev *led_cdev,
>> -			      struct led_init_data *init_data)
>> +int led_classdev_init(struct device *parent, struct led_classdev *led_cdev,
>> +		      struct led_init_data *init_data)
>>   {
>>   	char composed_name[LED_MAX_NAME_SIZE];
>>   	char final_name[LED_MAX_NAME_SIZE];
>> @@ -564,12 +573,52 @@ int led_classdev_register_ext(struct device *parent,
>>   	if (!led_cdev->max_brightness)
>>   		led_cdev->max_brightness = LED_FULL;
>>
>> +	led_cdev->dev = kzalloc_obj(*led_cdev->dev);
>> +	if (!led_cdev->dev)
>> +		return -ENOMEM;
>> +
>> +	device_initialize(led_cdev->dev);
>> +	led_cdev->dev->class = &leds_class;
>> +	led_cdev->dev->parent = parent;
>> +	led_cdev->dev->groups = led_cdev->groups;
>> +	dev_set_drvdata(led_cdev->dev, led_cdev);
>> +	ret = kobject_set_name(&led_cdev->dev->kobj, "%s", final_name);
>> +	if (ret) {
>> +		put_device(led_cdev->dev);
>> +		led_cdev->dev = NULL;
>> +		return ret;
>> +	}
>> +
>> +	led_cdev->wq = leds_wq;
>> +
>> +	led_init_core(led_cdev);
>> +
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(led_classdev_init);
>> +
>> +/**
>> + * led_classdev_add - Add a new LED class device to the subsystem.
>> + * @led_cdev: the led_classdev structure for this device.
>> + * @init_data: LED class device initialization data.
>> + *
>> + * Adds a new LED class device to the subsystem, allowing userspace applications
>> + * and/or kernel consumers to access it.
>> + *
>> + * Returns: Zero on success or a negative error code on failure.
>> + */
>> +int led_classdev_add(struct led_classdev *led_cdev, struct led_init_data *init_data)
>> +{
>> +	int ret;
>> +
>>   	mutex_lock(&led_cdev->led_access);
>> -	led_cdev->dev = device_create_with_groups(&leds_class, parent, 0,
>> -						  led_cdev, led_cdev->groups, "%s", final_name);
>> -	if (IS_ERR(led_cdev->dev)) {
>> +
>> +	ret = device_add(led_cdev->dev);
>> +	if (ret < 0) {
> Does (ret) work for this?

I believe so.

Thanks,
Armin Wolf

>>   		mutex_unlock(&led_cdev->led_access);
>> -		return PTR_ERR(led_cdev->dev);
>> +		put_device(led_cdev->dev);
>> +		led_cdev->dev = NULL;
>> +		return ret;
>>   	}
>>
>>   	if (init_data && init_data->fwnode)
>> @@ -588,10 +637,6 @@ int led_classdev_register_ext(struct device *parent,
>>
>>   	led_update_brightness(led_cdev);
>>
>> -	led_cdev->wq = leds_wq;
>> -
>> -	led_init_core(led_cdev);
>> -
>>   	/* add to the list of leds */
>>   	down_write(&leds_list_lock);
>>   	list_add_tail(&led_cdev->node, &leds_list);
>> @@ -603,11 +648,32 @@ int led_classdev_register_ext(struct device *parent,
>>
>>   	mutex_unlock(&led_cdev->led_access);
>>
>> -	dev_dbg(parent, "Registered led device: %s\n",
>> -			led_cdev->name);
>> +	dev_dbg(led_cdev->dev->parent, "Registered led device: %s\n", led_cdev->name);
>>
>>   	return 0;
>>   }
>> +EXPORT_SYMBOL_GPL(led_classdev_add);
>> +
>> +/**
>> + * led_classdev_register_ext - register a new object of led_classdev class
>> + *                             with init data.
>> + *
>> + * @parent: parent of LED device.
>> + * @led_cdev: the led_classdev structure for this device.
>> + * @init_data: LED class device initialization data.
>> + */
>> +int led_classdev_register_ext(struct device *parent,
>> +                              struct led_classdev *led_cdev,
>> +                              struct led_init_data *init_data)
>> +{
>> +	int ret;
>> +
>> +	ret = led_classdev_init(parent, led_cdev, init_data);
>> +	if (ret < 0)
> if (ret)
>
> ?
>
>> +		return ret;
>> +
>> +	return led_classdev_add(led_cdev, init_data);
>> +}
>>   EXPORT_SYMBOL_GPL(led_classdev_register_ext);
>>
>>   /**
>> diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
>> index 6d00e6f44126..def7166f062a 100644
>> --- a/drivers/leds/leds.h
>> +++ b/drivers/leds/leds.h
>> @@ -18,6 +18,9 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)
>>   }
>>
>>   void led_init_core(struct led_classdev *led_cdev);
>> +int led_classdev_init(struct device *parent, struct led_classdev *led_cdev,
>> +		      struct led_init_data *init_data);
>> +int led_classdev_add(struct led_classdev *led_cdev, struct led_init_data *init_data);
>>   void led_stop_software_blink(struct led_classdev *led_cdev);
>>   void led_set_brightness_nopm(struct led_classdev *led_cdev, unsigned int value);
>>   void led_set_brightness_nosleep(struct led_classdev *led_cdev, unsigned int value);
>> -- 
>> 2.56.1
>>

  reply	other threads:[~2026-11-28 13:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 21:22 [PATCH v3 00/11] leds: class: Support custom sysfs groups on multicolor and flash LEDs Armin Wolf
2026-11-20 21:22 ` [PATCH v3 01/11] leds: class: Constify sysfs attributes Armin Wolf
2026-11-20 21:22 ` [PATCH v3 02/11] leds: multicolor: " Armin Wolf
2026-11-20 21:22 ` [PATCH v3 03/11] leds: flash: " Armin Wolf
2026-11-20 21:22 ` [PATCH v3 04/11] leds: class: Create "brightness_hw_changed" attribute atomically Armin Wolf
2026-11-20 21:22 ` [PATCH v3 05/11] leds: class: Fix race condition when creating the device Armin Wolf
2026-11-20 21:22 ` [PATCH v3 06/11] leds: class: Access brightness_hw_changed exactly once Armin Wolf
2026-11-20 21:22 ` [PATCH v3 07/11] leds: class: Use correct type for brightness_hw_changed field Armin Wolf
2026-11-20 21:22 ` [PATCH v3 08/11] leds: class: Split led_classdev_register_ext() Armin Wolf
2026-11-27 14:42   ` Lee Jones
2026-11-28 13:24     ` Armin Wolf [this message]
2026-11-20 21:22 ` [PATCH v3 09/11] leds: Support custom sysfs groups on multicolor and flash LEDs Armin Wolf
2026-11-27 14:40   ` Lee Jones
2026-11-20 21:22 ` [PATCH v3 10/11] leds: rgb: ktd202x: Initialize max_brightness before registering LED Armin Wolf
2026-11-21 12:53   ` Armin Wolf
2026-11-27 14:39     ` Lee Jones
2026-11-20 21:22 ` [PATCH v3 11/11] leds: multicolor: Adjust maximum subled intensity during initialization Armin Wolf
2026-11-27 14:37   ` Lee Jones
2026-11-28 13:21     ` Armin Wolf
2026-11-21 11:21 ` [PATCH v3 00/11] leds: class: Support custom sysfs groups on multicolor and flash LEDs Rong Zhang
2026-11-21 12:42   ` 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=1bb5237d-17ba-4c5b-8f9a-15f06eb3c09b@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®