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

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 <linux@weissschuh.net>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Thomas Weißschuh and committed by
Lee Jones
563edf85 33a5471f

+17 -5
+17 -5
drivers/video/backlight/backlight.c
··· 292 292 struct backlight_device *bd = to_backlight_device(dev); 293 293 294 294 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 { 298 300 rc = sprintf(buf, "%d\n", bd->props.brightness); 301 + } 299 302 mutex_unlock(&bd->ops_lock); 300 303 301 304 return rc; ··· 384 381 void backlight_force_update(struct backlight_device *bd, 385 382 enum backlight_update_reason reason) 386 383 { 384 + int brightness; 385 + 387 386 mutex_lock(&bd->ops_lock); 388 - if (bd->ops && bd->ops->get_brightness) 389 - bd->props.brightness = bd->ops->get_brightness(bd); 387 + if (bd->ops && bd->ops->get_brightness) { 388 + brightness = bd->ops->get_brightness(bd); 389 + if (brightness >= 0) 390 + bd->props.brightness = brightness; 391 + else 392 + dev_err(&bd->dev, 393 + "Could not update brightness from device: %pe\n", 394 + ERR_PTR(brightness)); 395 + } 390 396 mutex_unlock(&bd->ops_lock); 391 397 backlight_generate_event(bd, reason); 392 398 }