* [PATCH 1/5] leds: led-test: Move common LED class registration code into helper function
@ 2025-05-14 16:27 Lee Jones
2025-05-14 16:27 ` [PATCH 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Lee Jones @ 2025-05-14 16:27 UTC (permalink / raw)
To: lee, bettyzhou, ynaffit, tkjos, jacek.anaszewski, Pavel Machek,
linux-leds, linux-kernel
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.1045.g170613ef41-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/5] leds: led-test: Provide test for registration with missing default_label
2025-05-14 16:27 [PATCH 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
@ 2025-05-14 16:27 ` Lee Jones
2025-05-14 16:27 ` [PATCH 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2025-05-14 16:27 UTC (permalink / raw)
To: lee, bettyzhou, ynaffit, tkjos, jacek.anaszewski, Pavel Machek,
linux-leds, linux-kernel
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..27c8d13bd2e1 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 = 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.1045.g170613ef41-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/5] leds: led-test: Provide test for registration with missing devicename
2025-05-14 16:27 [PATCH 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
2025-05-14 16:27 ` [PATCH 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
@ 2025-05-14 16:27 ` Lee Jones
2025-05-14 16:27 ` [PATCH 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
2025-05-14 16:27 ` [PATCH 5/5] leds: led-test: Provide test for successful registration using init_data Lee Jones
3 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2025-05-14 16:27 UTC (permalink / raw)
To: lee, bettyzhou, ynaffit, tkjos, jacek.anaszewski, Pavel Machek,
linux-leds, linux-kernel
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 27c8d13bd2e1..3d71c7a23e21 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 = 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.1045.g170613ef41-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/5] leds: led-test: Provide test for registration with a name that is too long
2025-05-14 16:27 [PATCH 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
2025-05-14 16:27 ` [PATCH 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
2025-05-14 16:27 ` [PATCH 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
@ 2025-05-14 16:27 ` Lee Jones
2025-05-14 16:27 ` [PATCH 5/5] leds: led-test: Provide test for successful registration using init_data Lee Jones
3 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2025-05-14 16:27 UTC (permalink / raw)
To: lee, bettyzhou, ynaffit, tkjos, jacek.anaszewski, Pavel Machek,
linux-leds, linux-kernel
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 3d71c7a23e21..741dc0269515 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 = 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.1045.g170613ef41-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 5/5] leds: led-test: Provide test for successful registration using init_data
2025-05-14 16:27 [PATCH 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
` (2 preceding siblings ...)
2025-05-14 16:27 ` [PATCH 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
@ 2025-05-14 16:27 ` Lee Jones
3 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2025-05-14 16:27 UTC (permalink / raw)
To: lee, bettyzhou, ynaffit, tkjos, jacek.anaszewski, Pavel Machek,
linux-leds, linux-kernel
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 741dc0269515..123e1feb835e 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 = 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.1045.g170613ef41-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-14 16:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14 16:27 [PATCH 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
2025-05-14 16:27 ` [PATCH 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
2025-05-14 16:27 ` [PATCH 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
2025-05-14 16:27 ` [PATCH 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
2025-05-14 16:27 ` [PATCH 5/5] leds: led-test: Provide test for successful registration using init_data Lee Jones
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.