From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, bettyzhou@google.com, ynaffit@google.com,
tkjos@google.com, jacek.anaszewski@gmail.com,
Pavel Machek <pavel@kernel.org>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] leds: led-test: Move common LED class registration code into helper function
Date: Wed, 14 May 2025 17:27:52 +0100 [thread overview]
Message-ID: <20250514162807.708010-1-lee@kernel.org> (raw)
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
next reply other threads:[~2025-05-14 16:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-14 16:27 Lee Jones [this message]
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
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=20250514162807.708010-1-lee@kernel.org \
--to=lee@kernel.org \
--cc=bettyzhou@google.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=tkjos@google.com \
--cc=ynaffit@google.com \
/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 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.