Skip to content

Commit 563edf8

Browse files
t-8chLee Jones
authored andcommitted
backlight: Propagate errors from get_brightness()
backlight.h documents "struct backlight_ops->get_brightness()" to return a negative errno on failure. So far these errors have not been handled in the backlight core. This leads to negative values being exposed through sysfs although only positive values are documented to be reported. Signed-off-by: Thomas Weißschuh <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent 33a5471 commit 563edf8

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

drivers/video/backlight/backlight.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,13 @@ static ssize_t actual_brightness_show(struct device *dev,
292292
struct backlight_device *bd = to_backlight_device(dev);
293293

294294
mutex_lock(&bd->ops_lock);
295-
if (bd->ops && bd->ops->get_brightness)
296-
rc = sprintf(buf, "%d\n", bd->ops->get_brightness(bd));
297-
else
295+
if (bd->ops && bd->ops->get_brightness) {
296+
rc = bd->ops->get_brightness(bd);
297+
if (rc >= 0)
298+
rc = sprintf(buf, "%d\n", rc);
299+
} else {
298300
rc = sprintf(buf, "%d\n", bd->props.brightness);
301+
}
299302
mutex_unlock(&bd->ops_lock);
300303

301304
return rc;
@@ -381,9 +384,18 @@ ATTRIBUTE_GROUPS(bl_device);
381384
void backlight_force_update(struct backlight_device *bd,
382385
enum backlight_update_reason reason)
383386
{
387+
int brightness;
388+
384389
mutex_lock(&bd->ops_lock);
385-
if (bd->ops && bd->ops->get_brightness)
386-
bd->props.brightness = bd->ops->get_brightness(bd);
390+
if (bd->ops && bd->ops->get_brightness) {
391+
brightness = bd->ops->get_brightness(bd);
392+
if (brightness >= 0)
393+
bd->props.brightness = brightness;
394+
else
395+
dev_err(&bd->dev,
396+
"Could not update brightness from device: %pe\n",
397+
ERR_PTR(brightness));
398+
}
387399
mutex_unlock(&bd->ops_lock);
388400
backlight_generate_event(bd, reason);
389401
}

0 commit comments

Comments
 (0)