mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] video: backlight: make brightness and slew time parameters unsigned
Date: Mon,  1 Jul 2024 09:27:14 +0200	[thread overview]
Message-ID: <20240701072714.163239-1-a.fatoum@pengutronix.de> (raw)

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




             reply	other threads:[~2024-07-01  7:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-01  7:27 Ahmad Fatoum [this message]
2024-07-01  9:57 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240701072714.163239-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox