Skip to content

Commit 3ef7de5

Browse files
janaszewskicooloney
authored andcommitted
leds: Improve and export led_update_brightness
led_update_brightness helper function used to be exploited only locally in the led-class.c module, where its result was being passed to the brightness_show sysfs callback. With the introduction of v4l2-flash subdevice the same functionality becomes required for reading current brightness from a LED device. This patch adds checking of return value of the brightness_get callback and moves the led_update_brightness() function to the LED subsystem public API. Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com> Acked-by: Kyungmin Park <kyungmin.park@samsung.com> Cc: Richard Purdie <rpurdie@rpsys.net> Signed-off-by: Bryan Wu <cooloney@gmail.com>
1 parent 914ae25 commit 3ef7de5

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎drivers/leds/led-class.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424

2525
static struct class *leds_class;
2626

27-
static void led_update_brightness(struct led_classdev *led_cdev)
28-
{
29-
if (led_cdev->brightness_get)
30-
led_cdev->brightness = led_cdev->brightness_get(led_cdev);
31-
}
32-
3327
static ssize_t brightness_show(struct device *dev,
3428
struct device_attribute *attr, char *buf)
3529
{

‎drivers/leds/led-core.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev,
127127
__led_set_brightness(led_cdev, brightness);
128128
}
129129
EXPORT_SYMBOL(led_set_brightness);
130+
131+
int led_update_brightness(struct led_classdev *led_cdev)
132+
{
133+
int ret = 0;
134+
135+
if (led_cdev->brightness_get) {
136+
ret = led_cdev->brightness_get(led_cdev);
137+
if (ret >= 0) {
138+
led_cdev->brightness = ret;
139+
return 0;
140+
}
141+
}
142+
143+
return ret;
144+
}
145+
EXPORT_SYMBOL(led_update_brightness);

‎include/linux/leds.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,
140140
*/
141141
extern void led_set_brightness(struct led_classdev *led_cdev,
142142
enum led_brightness brightness);
143+
/**
144+
* led_update_brightness - update LED brightness
145+
* @led_cdev: the LED to query
146+
*
147+
* Get an LED's current brightness and update led_cdev->brightness
148+
* member with the obtained value.
149+
*
150+
* Returns: 0 on success or negative error value on failure
151+
*/
152+
extern int led_update_brightness(struct led_classdev *led_cdev);
143153

144154
/*
145155
* LED Triggers

0 commit comments

Comments
 (0)