mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] video: backlight: make brightness and slew time parameters unsigned
@ 2024-07-01  7:27 Ahmad Fatoum
  2024-07-01  9:57 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-01  7:27 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Despite the backlight parameter being registered as uint32,
backlight_brightness_set took the brightness level as a signed value.

This can lead to wrap around for very large values of brightness
supplied as device parameter and if this results in a negative
brightness, the function appears to hang, because the slew rate loop
runs for a long time.

Fix this by making brightness level an unsigned entity.

Fixes: e3ea90860e99 ("video: Add backlight support")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/video/backlight.c | 6 +++---
 include/video/backlight.h | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/video/backlight.c b/drivers/video/backlight.c
index 6c00cc115e6d..d171b0d960d2 100644
--- a/drivers/video/backlight.c
+++ b/drivers/video/backlight.c
@@ -6,7 +6,7 @@
 
 static LIST_HEAD(backlights);
 
-int backlight_set_brightness(struct backlight_device *bl, int brightness)
+int backlight_set_brightness(struct backlight_device *bl, unsigned brightness)
 {
 	int ret, step, i, num_steps;
 
@@ -80,9 +80,9 @@ int backlight_register(struct backlight_device *bl)
 		return ret;
 
 	dev_add_param_uint32(&bl->dev, "brightness", backlight_brightness_set,
-			NULL, &bl->brightness, "%d", bl);
+			NULL, &bl->brightness, "%u", bl);
 	dev_add_param_uint32(&bl->dev, "slew_time_ms", NULL, NULL,
-			     &bl->slew_time_ms, "%d", NULL);
+			     &bl->slew_time_ms, "%u", NULL);
 
 	list_add_tail(&bl->list, &backlights);
 
diff --git a/include/video/backlight.h b/include/video/backlight.h
index b510de9d294f..2dd63202cd6e 100644
--- a/include/video/backlight.h
+++ b/include/video/backlight.h
@@ -16,7 +16,7 @@ struct backlight_device {
 	struct device_node *node;
 };
 
-int backlight_set_brightness(struct backlight_device *, int brightness);
+int backlight_set_brightness(struct backlight_device *, unsigned brightness);
 int backlight_set_brightness_default(struct backlight_device *);
 int backlight_register(struct backlight_device *);
 struct backlight_device *of_backlight_find(struct device_node *node);
@@ -24,7 +24,7 @@ struct backlight_device *of_backlight_find(struct device_node *node);
 struct backlight_device ;
 
 static inline int
-backlight_set_brightness(struct backlight_device *dev, int brightness)
+backlight_set_brightness(struct backlight_device *dev, unsigned brightness)
 {
 	return 0;
 }
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH master] video: backlight: make brightness and slew time parameters unsigned
  2024-07-01  7:27 [PATCH master] video: backlight: make brightness and slew time parameters unsigned Ahmad Fatoum
@ 2024-07-01  9:57 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-07-01  9:57 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 01 Jul 2024 09:27:14 +0200, Ahmad Fatoum wrote:
> Despite the backlight parameter being registered as uint32,
> backlight_brightness_set took the brightness level as a signed value.
> 
> This can lead to wrap around for very large values of brightness
> supplied as device parameter and if this results in a negative
> brightness, the function appears to hang, because the slew rate loop
> runs for a long time.
> 
> [...]

Applied, thanks!

[1/1] video: backlight: make brightness and slew time parameters unsigned
      https://git.pengutronix.de/cgit/barebox/commit/?id=7b4c629a16ae (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-01  9:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-01  7:27 [PATCH master] video: backlight: make brightness and slew time parameters unsigned Ahmad Fatoum
2024-07-01  9:57 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox