Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: core: Introduce led_get_color_name() function

This is similar to the existing led_colors[] array but is safer to use and
usable by everyone.

Getting string representations of color ids is useful for drivers
which are handling color IDs anyways, for example for the multicolor API.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20240613-cros_ec-led-v3-1-500b50f41e0f@weissschuh.net
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Thomas Weißschuh and committed by
Lee Jones
5f2e9507 1613e604

+19
+9
drivers/leds/led-core.c
··· 534 534 } 535 535 EXPORT_SYMBOL_GPL(led_compose_name); 536 536 537 + const char *led_get_color_name(u8 color_id) 538 + { 539 + if (color_id >= ARRAY_SIZE(led_colors)) 540 + return NULL; 541 + 542 + return led_colors[color_id]; 543 + } 544 + EXPORT_SYMBOL_GPL(led_get_color_name); 545 + 537 546 enum led_default_state led_init_default_state_get(struct fwnode_handle *fwnode) 538 547 { 539 548 const char *state = NULL;
+10
include/linux/leds.h
··· 428 428 char *led_classdev_name); 429 429 430 430 /** 431 + * led_get_color_name - get string representation of color ID 432 + * @color_id: The LED_COLOR_ID_* constant 433 + * 434 + * Get the string name of a LED_COLOR_ID_* constant. 435 + * 436 + * Returns: A string constant or NULL on an invalid ID. 437 + */ 438 + const char *led_get_color_name(u8 color_id); 439 + 440 + /** 431 441 * led_sysfs_is_disabled - check if LED sysfs interface is disabled 432 442 * @led_cdev: the LED to query 433 443 *