* [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data
@ 2025-05-15 8:27 Lee Jones
2025-05-15 8:28 ` [PATCH v2 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Lee Jones @ 2025-05-15 8:27 UTC (permalink / raw)
To: lee, Pavel Machek, linux-leds, linux-kernel
Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski
Lots of drivers still register with the LED Class using init_data. Let's
provide some additional Kunit infrastructure to exercise the various
possibilities.
Change log:
v1 => v2:
- Use devm_* to ensure resources are cleaned-up on exit
Lee Jones (5):
leds: led-test: Move common LED class registration code into helper
function
leds: led-test: Provide test for registration with missing
default_label
leds: led-test: Provide test for registration with missing devicename
leds: led-test: Provide test for registration with a name that is too
long
leds: led-test: Provide test for successful registration using
init_data
drivers/leds/led-test.c | 86 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 80 insertions(+), 6 deletions(-)
--
2.49.0.1101.gccaa498523-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/5] leds: led-test: Move common LED class registration code into helper function
2025-05-15 8:27 [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Lee Jones
@ 2025-05-15 8:28 ` Lee Jones
2025-05-15 8:28 ` [PATCH v2 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2025-05-15 8:28 UTC (permalink / raw)
To: lee, Pavel Machek, linux-leds, linux-kernel
Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski
Since we will always need to register an LED class, it makes sense to
avoid duplicating this part over and over.
Returning void and not propagating errors is expected here since the
assert will terminate the process early if an error condition is
encountered.
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/leds/led-test.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c
index ddf9aa967a6a..0f152fb12dfb 100644
--- a/drivers/leds/led-test.c
+++ b/drivers/leds/led-test.c
@@ -22,10 +22,10 @@ static enum led_brightness led_test_brightness_get(struct led_classdev *cdev)
return LED_TEST_POST_REG_BRIGHTNESS;
}
-static void led_test_class_register(struct kunit *test)
+static void led_test_class_register_helper(struct kunit *test)
{
struct led_test_ddata *ddata = test->priv;
- struct led_classdev *cdev_clash, *cdev = &ddata->cdev;
+ struct led_classdev *cdev = &ddata->cdev;
struct device *dev = ddata->dev;
int ret;
@@ -36,6 +36,17 @@ static void led_test_class_register(struct kunit *test)
ret = devm_led_classdev_register(dev, cdev);
KUNIT_ASSERT_EQ(test, ret, 0);
+}
+
+static void led_test_class_register(struct kunit *test)
+{
+ struct led_test_ddata *ddata = test->priv;
+ struct led_classdev *cdev_clash, *cdev = &ddata->cdev;
+ struct device *dev = ddata->dev;
+ int ret;
+
+ /* Register initial device - same as always */
+ led_test_class_register_helper(test);
KUNIT_EXPECT_EQ(test, cdev->max_brightness, LED_FULL);
KUNIT_EXPECT_EQ(test, cdev->brightness, LED_TEST_POST_REG_BRIGHTNESS);
@@ -63,12 +74,9 @@ static void led_test_class_add_lookup_and_get(struct kunit *test)
struct led_classdev *cdev = &ddata->cdev, *cdev_get;
struct device *dev = ddata->dev;
struct led_lookup_data lookup;
- int ret;
/* First, register a LED class device */
- cdev->name = "led-test";
- ret = devm_led_classdev_register(dev, cdev);
- KUNIT_ASSERT_EQ(test, ret, 0);
+ led_test_class_register_helper(test);
/* Then make the LED available for lookup */
lookup.provider = cdev->name;
--
2.49.0.1101.gccaa498523-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/5] leds: led-test: Provide test for registration with missing default_label
2025-05-15 8:27 [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Lee Jones
2025-05-15 8:28 ` [PATCH v2 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
@ 2025-05-15 8:28 ` Lee Jones
2025-05-15 8:28 ` [PATCH v2 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2025-05-15 8:28 UTC (permalink / raw)
To: lee, Pavel Machek, linux-leds, linux-kernel
Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski
Insist on legacy (non-DT) registration and omit the default_label, which
should fail with an invalid argument error.
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/leds/led-test.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c
index 0f152fb12dfb..760c393f5c5d 100644
--- a/drivers/leds/led-test.c
+++ b/drivers/leds/led-test.c
@@ -93,9 +93,25 @@ static void led_test_class_add_lookup_and_get(struct kunit *test)
led_remove_lookup(&lookup);
}
+static void led_test_class_init_data_missing_default_label(struct kunit *test)
+{
+ struct led_test_ddata *ddata = test->priv;
+ struct led_classdev *cdev = &ddata->cdev;
+ struct device *dev = ddata->dev;
+ int ret;
+
+ struct led_init_data init_data = {
+ .devicename = "led-test-devicename",
+ };
+
+ ret = devm_led_classdev_register_ext(dev, cdev, &init_data);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
+
static struct kunit_case led_test_cases[] = {
KUNIT_CASE(led_test_class_register),
KUNIT_CASE(led_test_class_add_lookup_and_get),
+ KUNIT_CASE(led_test_class_init_data_missing_default_label),
{ }
};
--
2.49.0.1101.gccaa498523-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/5] leds: led-test: Provide test for registration with missing devicename
2025-05-15 8:27 [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Lee Jones
2025-05-15 8:28 ` [PATCH v2 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
2025-05-15 8:28 ` [PATCH v2 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
@ 2025-05-15 8:28 ` Lee Jones
2025-05-15 8:28 ` [PATCH v2 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2025-05-15 8:28 UTC (permalink / raw)
To: lee, Pavel Machek, linux-leds, linux-kernel
Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski
Insist on legacy (non-DT) registration and omit the devicename, which
should fail with an invalid argument error.
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/leds/led-test.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c
index 760c393f5c5d..d378c905546b 100644
--- a/drivers/leds/led-test.c
+++ b/drivers/leds/led-test.c
@@ -108,10 +108,26 @@ static void led_test_class_init_data_missing_default_label(struct kunit *test)
KUNIT_EXPECT_EQ(test, ret, -EINVAL);
}
+static void led_test_class_init_data_missing_devicename(struct kunit *test)
+{
+ struct led_test_ddata *ddata = test->priv;
+ struct led_classdev *cdev = &ddata->cdev;
+ struct device *dev = ddata->dev;
+ int ret;
+
+ struct led_init_data init_data = {
+ .default_label = "led-test-label",
+ };
+
+ ret = devm_led_classdev_register_ext(dev, cdev, &init_data);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
+
static struct kunit_case led_test_cases[] = {
KUNIT_CASE(led_test_class_register),
KUNIT_CASE(led_test_class_add_lookup_and_get),
KUNIT_CASE(led_test_class_init_data_missing_default_label),
+ KUNIT_CASE(led_test_class_init_data_missing_devicename),
{ }
};
--
2.49.0.1101.gccaa498523-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/5] leds: led-test: Provide test for registration with a name that is too long
2025-05-15 8:27 [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Lee Jones
` (2 preceding siblings ...)
2025-05-15 8:28 ` [PATCH v2 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
@ 2025-05-15 8:28 ` Lee Jones
2025-05-15 8:28 ` [PATCH v2 5/5] leds: led-test: Provide test for successful registration using init_data Lee Jones
2025-05-18 15:32 ` [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Jacek Anaszewski
5 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2025-05-15 8:28 UTC (permalink / raw)
To: lee, Pavel Machek, linux-leds, linux-kernel
Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski
Insist on legacy (non-DT) registration and provide a default_label and
devicename that when concatenated together results in a device name that
is unacceptably long.
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/leds/led-test.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c
index d378c905546b..d5017c6dca08 100644
--- a/drivers/leds/led-test.c
+++ b/drivers/leds/led-test.c
@@ -123,11 +123,28 @@ static void led_test_class_init_data_missing_devicename(struct kunit *test)
KUNIT_EXPECT_EQ(test, ret, -EINVAL);
}
+static void led_test_class_init_data_name_too_long(struct kunit *test)
+{
+ struct led_test_ddata *ddata = test->priv;
+ struct led_classdev *cdev = &ddata->cdev;
+ struct device *dev = ddata->dev;
+ int ret;
+
+ struct led_init_data init_data = {
+ .devicename = "led-test-devicename-very-long-names-fail",
+ .default_label = "led-test-label-also-very-long-names-fail",
+ };
+
+ ret = devm_led_classdev_register_ext(dev, cdev, &init_data);
+ KUNIT_EXPECT_EQ(test, ret, -E2BIG);
+}
+
static struct kunit_case led_test_cases[] = {
KUNIT_CASE(led_test_class_register),
KUNIT_CASE(led_test_class_add_lookup_and_get),
KUNIT_CASE(led_test_class_init_data_missing_default_label),
KUNIT_CASE(led_test_class_init_data_missing_devicename),
+ KUNIT_CASE(led_test_class_init_data_name_too_long),
{ }
};
--
2.49.0.1101.gccaa498523-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/5] leds: led-test: Provide test for successful registration using init_data
2025-05-15 8:27 [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Lee Jones
` (3 preceding siblings ...)
2025-05-15 8:28 ` [PATCH v2 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
@ 2025-05-15 8:28 ` Lee Jones
2025-05-18 15:32 ` [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Jacek Anaszewski
5 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2025-05-15 8:28 UTC (permalink / raw)
To: lee, Pavel Machek, linux-leds, linux-kernel
Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski
This time both the default_label and devicename are provided such that
when concatenated together result in a device name that is acceptable.
In this case registration should succeed.
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/leds/led-test.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c
index d5017c6dca08..9bdebbe04462 100644
--- a/drivers/leds/led-test.c
+++ b/drivers/leds/led-test.c
@@ -139,12 +139,29 @@ static void led_test_class_init_data_name_too_long(struct kunit *test)
KUNIT_EXPECT_EQ(test, ret, -E2BIG);
}
+static void led_test_class_init_data(struct kunit *test)
+{
+ struct led_test_ddata *ddata = test->priv;
+ struct led_classdev *cdev = &ddata->cdev;
+ struct device *dev = ddata->dev;
+ int ret;
+
+ struct led_init_data init_data = {
+ .devicename = "led-test-devicename",
+ .default_label = "led-test-label",
+ };
+
+ ret = devm_led_classdev_register_ext(dev, cdev, &init_data);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+}
+
static struct kunit_case led_test_cases[] = {
KUNIT_CASE(led_test_class_register),
KUNIT_CASE(led_test_class_add_lookup_and_get),
KUNIT_CASE(led_test_class_init_data_missing_default_label),
KUNIT_CASE(led_test_class_init_data_missing_devicename),
KUNIT_CASE(led_test_class_init_data_name_too_long),
+ KUNIT_CASE(led_test_class_init_data),
{ }
};
--
2.49.0.1101.gccaa498523-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data
2025-05-15 8:27 [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Lee Jones
` (4 preceding siblings ...)
2025-05-15 8:28 ` [PATCH v2 5/5] leds: led-test: Provide test for successful registration using init_data Lee Jones
@ 2025-05-18 15:32 ` Jacek Anaszewski
2025-05-19 13:33 ` Lee Jones
5 siblings, 1 reply; 9+ messages in thread
From: Jacek Anaszewski @ 2025-05-18 15:32 UTC (permalink / raw)
To: Lee Jones, Pavel Machek, linux-leds, linux-kernel
Cc: bettyzhou, ynaffit, tkjos
Hi Lee,
On 5/15/25 10:27, Lee Jones wrote:
> Lots of drivers still register with the LED Class using init_data. Let's
What do you mean by "still"? Actually init_data is the new approach,
that turns the LED core DT parser on, and is predestined for use with
{devm_}led_classdev_register_ext() API.
> provide some additional Kunit infrastructure to exercise the various
> possibilities.
>
> Change log:
>
> v1 => v2:
> - Use devm_* to ensure resources are cleaned-up on exit
>
> Lee Jones (5):
> leds: led-test: Move common LED class registration code into helper
> function
> leds: led-test: Provide test for registration with missing
> default_label
> leds: led-test: Provide test for registration with missing devicename
> leds: led-test: Provide test for registration with a name that is too
> long
> leds: led-test: Provide test for successful registration using
> init_data
>
> drivers/leds/led-test.c | 86 ++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 80 insertions(+), 6 deletions(-)
>
--
Best regards,
Jacek Anaszewski
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data
2025-05-18 15:32 ` [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Jacek Anaszewski
@ 2025-05-19 13:33 ` Lee Jones
2025-05-21 21:26 ` Jacek Anaszewski
0 siblings, 1 reply; 9+ messages in thread
From: Lee Jones @ 2025-05-19 13:33 UTC (permalink / raw)
To: Jacek Anaszewski
Cc: Pavel Machek, linux-leds, linux-kernel, bettyzhou, ynaffit, tkjos
On Sun, 18 May 2025, Jacek Anaszewski wrote:
> Hi Lee,
>
> On 5/15/25 10:27, Lee Jones wrote:
> > Lots of drivers still register with the LED Class using init_data. Let's
>
> What do you mean by "still"? Actually init_data is the new approach,
> that turns the LED core DT parser on, and is predestined for use with
> {devm_}led_classdev_register_ext() API.
Thanks for the information. I'll update the wording.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data
2025-05-19 13:33 ` Lee Jones
@ 2025-05-21 21:26 ` Jacek Anaszewski
0 siblings, 0 replies; 9+ messages in thread
From: Jacek Anaszewski @ 2025-05-21 21:26 UTC (permalink / raw)
To: Lee Jones
Cc: Pavel Machek, linux-leds, linux-kernel, bettyzhou, ynaffit, tkjos
On 5/19/25 15:33, Lee Jones wrote:
> On Sun, 18 May 2025, Jacek Anaszewski wrote:
>
>> Hi Lee,
>>
>> On 5/15/25 10:27, Lee Jones wrote:
>>> Lots of drivers still register with the LED Class using init_data. Let's
>>
>> What do you mean by "still"? Actually init_data is the new approach,
>> that turns the LED core DT parser on, and is predestined for use with
>> {devm_}led_classdev_register_ext() API.
>
> Thanks for the information. I'll update the wording.
Other than that, for the whole series:
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
--
Best regards,
Jacek Anaszewski
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-05-21 21:26 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-15 8:27 [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Lee Jones
2025-05-15 8:28 ` [PATCH v2 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
2025-05-15 8:28 ` [PATCH v2 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
2025-05-15 8:28 ` [PATCH v2 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
2025-05-15 8:28 ` [PATCH v2 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
2025-05-15 8:28 ` [PATCH v2 5/5] leds: led-test: Provide test for successful registration using init_data Lee Jones
2025-05-18 15:32 ` [PATCH v2 0/5] leds: KUnit registration tests pertaining to init_data Jacek Anaszewski
2025-05-19 13:33 ` Lee Jones
2025-05-21 21:26 ` Jacek Anaszewski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.