Skip to contentSkip to conversation

backlight: propagate errors from get_brightness()

PATCH Applied Thomas Weißschuh 3 participants 8 messages Sep 7, 2021 – Sep 23, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---

v1: https://lore.kernel.org/dri-devel/[email protected]/

v1 -> v2:
* use dev_err() instead of dev_warn() (Daniel Thompson)
* Finish logging format string with newline (Daniel Thompson)
* Log errno via dedicated error pointer format (Daniel Thompson)

 drivers/video/backlight/backlight.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/video/backlight/backlight.c +17 -5
index 537fe1b376ad..4658cfb75aa2 100644
@@ -292,10 +292,13 @@ static ssize_t actual_brightness_show(struct device *dev,
 	struct backlight_device *bd = to_backlight_device(dev);
 
 	mutex_lock(&bd->ops_lock);
-	if (bd->ops && bd->ops->get_brightness)
-		rc = sprintf(buf, "%d\n", bd->ops->get_brightness(bd));
-	else
+	if (bd->ops && bd->ops->get_brightness) {
+		rc = bd->ops->get_brightness(bd);
+		if (rc >= 0)
+			rc = sprintf(buf, "%d\n", rc);
+	} else {
 		rc = sprintf(buf, "%d\n", bd->props.brightness);
+	}
 	mutex_unlock(&bd->ops_lock);
 
 	return rc;
@@ -381,9 +384,18 @@ ATTRIBUTE_GROUPS(bl_device);
 void backlight_force_update(struct backlight_device *bd,
 			    enum backlight_update_reason reason)
 {
+	int brightness;
+
 	mutex_lock(&bd->ops_lock);
-	if (bd->ops && bd->ops->get_brightness)
-		bd->props.brightness = bd->ops->get_brightness(bd);
+	if (bd->ops && bd->ops->get_brightness) {
+		brightness = bd->ops->get_brightness(bd);
+		if (brightness >= 0)
+			bd->props.brightness = brightness;
+		else
+			dev_err(&bd->dev,
+				"Could not update brightness from device: %pe\n",
+				ERR_PTR(brightness));
+	}
 	mutex_unlock(&bd->ops_lock);
 	backlight_generate_event(bd, reason);
 }

base-commit: 79fad92f2e596f5a8dd085788a24f540263ef887

Signature · 1 line
2.33.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Thomas Weißschuh

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.

Quoted 59 lines

---

v1: https://lore.kernel.org/dri-devel/[email protected]/

v1 -> v2:
* use dev_err() instead of dev_warn() (Daniel Thompson)
* Finish logging format string with newline (Daniel Thompson)
* Log errno via dedicated error pointer format (Daniel Thompson)

 drivers/video/backlight/backlight.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/video/backlight/backlight.c +17 -5
index 537fe1b376ad..4658cfb75aa2 100644
@@ -292,10 +292,13 @@ static ssize_t actual_brightness_show(struct device *dev,
 	struct backlight_device *bd = to_backlight_device(dev);
 
 	mutex_lock(&bd->ops_lock);
-	if (bd->ops && bd->ops->get_brightness)
-		rc = sprintf(buf, "%d\n", bd->ops->get_brightness(bd));
-	else
+	if (bd->ops && bd->ops->get_brightness) {
+		rc = bd->ops->get_brightness(bd);
+		if (rc >= 0)
+			rc = sprintf(buf, "%d\n", rc);
+	} else {
 		rc = sprintf(buf, "%d\n", bd->props.brightness);
+	}
 	mutex_unlock(&bd->ops_lock);
 
 	return rc;
@@ -381,9 +384,18 @@ ATTRIBUTE_GROUPS(bl_device);
 void backlight_force_update(struct backlight_device *bd,
 			    enum backlight_update_reason reason)
 {
+	int brightness;
+
 	mutex_lock(&bd->ops_lock);
-	if (bd->ops && bd->ops->get_brightness)
-		bd->props.brightness = bd->ops->get_brightness(bd);
+	if (bd->ops && bd->ops->get_brightness) {
+		brightness = bd->ops->get_brightness(bd);
+		if (brightness >= 0)
+			bd->props.brightness = brightness;
+		else
+			dev_err(&bd->dev,
+				"Could not update brightness from device: %pe\n",
+				ERR_PTR(brightness));
+	}
 	mutex_unlock(&bd->ops_lock);
 	backlight_generate_event(bd, reason);
 }

base-commit: 79fad92f2e596f5a8dd085788a24f540263ef887

Signature · 1 line
2.33.0
#2 lore raw
Quoted 10 lines · Daniel Thompson
Quoted 7 lines · Thomas Weißschuh

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.

Thanks!

Thomas

#3 lore raw
In reply to Thomas Weißschuh
Quoted 7 lines · Thomas Weißschuh

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.

[..]

Friendly ping.

#4 lore raw
Quoted 10 lines · Thomas Weißschuh
Quoted 7 lines · Thomas Weißschuh

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.

[..]

Friendly ping.

Don't do that. If you think the submission has been forgotten about (it hasn't), then please submit a [RESEND]. As it happens, this is on my TOREVEW list. I just need to get around to it post-vacation.

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
Applied
#5 lore raw
In reply to Thomas Weißschuh
Quoted 11 lines · Thomas Weißschuh

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.

---

v1: https://lore.kernel.org/dri-devel/[email protected]/

Quoted 7 lines

v1 -> v2:
* use dev_err() instead of dev_warn() (Daniel Thompson)
* Finish logging format string with newline (Daniel Thompson)
* Log errno via dedicated error pointer format (Daniel Thompson)

 drivers/video/backlight/backlight.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#6 lore raw
Quoted 18 lines · Lee Jones
Quoted 16 lines · Thomas Weißschuh

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.

---

v1: https://lore.kernel.org/dri-devel/[email protected]/

v1 -> v2:
* use dev_err() instead of dev_warn() (Daniel Thompson)
* Finish logging format string with newline (Daniel Thompson)
* Log errno via dedicated error pointer format (Daniel Thompson)

Quoted 4 lines
Quoted 2 lines
 drivers/video/backlight/backlight.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

Applied, thanks.

Hi Lee,

thanks!

Also I'm sorry about my nagging before.
I was not aware you were on vacation and saw you respond to other mails.

Thomas

#7 lore raw
Quoted 22 lines · Thomas Weißschuh
Quoted 21 lines · Lee Jones
Quoted 18 lines · Thomas Weißschuh

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.

---

v1: https://lore.kernel.org/dri-devel/[email protected]/

v1 -> v2:
* use dev_err() instead of dev_warn() (Daniel Thompson)
* Finish logging format string with newline (Daniel Thompson)
* Log errno via dedicated error pointer format (Daniel Thompson)

 drivers/video/backlight/backlight.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 1 line

Applied, thanks.

Hi Lee,

thanks!

Also I'm sorry about my nagging before.

No worries.

Quoted 1 line

I was not aware you were on vacation and saw you respond to other mails.

They were in the queue before this one.

I had hundreds of emails to get through on my return!

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog