linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/5] leds: led-test: Move common LED class registration code into helper function
@ 2025-05-22  8:06 Lee Jones
  2025-05-22  8:06 ` [PATCH v3 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-22  8:06 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>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
---
 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.1143.g0be31eac6b-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/5] leds: led-test: Provide test for registration with missing default_label
  2025-05-22  8:06 [PATCH v3 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
@ 2025-05-22  8:06 ` Lee Jones
  2025-05-22  8:06 ` [PATCH v3 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-22  8:06 UTC (permalink / raw)
  To: lee, Pavel Machek, linux-leds, linux-kernel
  Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski

Insist on non-DT registration with init_data, but omit the
default_label, which should fail with an invalid argument error.

Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
---
 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.1143.g0be31eac6b-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/5] leds: led-test: Provide test for registration with missing devicename
  2025-05-22  8:06 [PATCH v3 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
  2025-05-22  8:06 ` [PATCH v3 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
@ 2025-05-22  8:06 ` Lee Jones
  2025-05-22  8:06 ` [PATCH v3 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
  2025-05-22  8:06 ` [PATCH v3 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-22  8:06 UTC (permalink / raw)
  To: lee, Pavel Machek, linux-leds, linux-kernel
  Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski

Insist on non-DT registration with init_data, but omit the devicename,
which should fail with an invalid argument error.

Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
---
 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.1143.g0be31eac6b-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 4/5] leds: led-test: Provide test for registration with a name that is too long
  2025-05-22  8:06 [PATCH v3 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
  2025-05-22  8:06 ` [PATCH v3 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
  2025-05-22  8:06 ` [PATCH v3 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
@ 2025-05-22  8:06 ` Lee Jones
  2025-05-22  8:06 ` [PATCH v3 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-22  8:06 UTC (permalink / raw)
  To: lee, Pavel Machek, linux-leds, linux-kernel
  Cc: bettyzhou, ynaffit, tkjos, jacek.anaszewski

Insist on non-DT registration with init_data whilst providing 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>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
---
 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.1143.g0be31eac6b-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 5/5] leds: led-test: Provide test for successful registration using init_data
  2025-05-22  8:06 [PATCH v3 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
                   ` (2 preceding siblings ...)
  2025-05-22  8:06 ` [PATCH v3 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
@ 2025-05-22  8:06 ` Lee Jones
  3 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2025-05-22  8:06 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>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
---
 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.1143.g0be31eac6b-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-22  8:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22  8:06 [PATCH v3 1/5] leds: led-test: Move common LED class registration code into helper function Lee Jones
2025-05-22  8:06 ` [PATCH v3 2/5] leds: led-test: Provide test for registration with missing default_label Lee Jones
2025-05-22  8:06 ` [PATCH v3 3/5] leds: led-test: Provide test for registration with missing devicename Lee Jones
2025-05-22  8:06 ` [PATCH v3 4/5] leds: led-test: Provide test for registration with a name that is too long Lee Jones
2025-05-22  8:06 ` [PATCH v3 5/5] leds: led-test: Provide test for successful registration using init_data Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).