summaryrefslogtreecommitdiffstats
path: root/drivers/video
diff options
context:
space:
mode:
authoriw3gtf@arcor.de <iw3gtf@arcor.de>2016-07-14 16:17:18 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-07-15 08:07:14 +0200
commit832f9fec6a0c0d0e37a1610f267b4ffdd8c8895e (patch)
treec5027a652770b4bcfe0e9215e2d4e5ffbeca6c86 /drivers/video
parentca497ce66d6aa33838c6ebf587ee2a25d1910439 (diff)
downloadbarebox-832f9fec6a0c0d0e37a1610f267b4ffdd8c8895e.tar.gz
barebox-832f9fec6a0c0d0e37a1610f267b4ffdd8c8895e.tar.xz
video/backlight-pwm: properly handle the case of an empty 'brightness-levels' in the device tree.
In case of an empty 'brightness-levels' array in the device tree or a non empty one but containing only zeros the value of 'pwm_backlight->scale' would remain 0 possibly causing a division by zero in the function compute_duty_cycle(). To fix it we check the computed value in case we actually have a 'brightness-levels' array in the device tree otherwise we implicitly assume a simple array of the form { 0, 1, 2, ..., 100 } and set the scale to 100. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/backlight-pwm.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
index 5ff40a94c3..7f1715ddde 100644
--- a/drivers/video/backlight-pwm.c
+++ b/drivers/video/backlight-pwm.c
@@ -128,6 +128,13 @@ static int pwm_backlight_parse_dt(struct device_d *dev,
if (!node)
return -ENODEV;
+ ret = of_property_read_u32(node, "default-brightness-level",
+ &value);
+ if (ret < 0)
+ return ret;
+
+ pwm_backlight->backlight.brightness_default = value;
+
/* determine the number of brightness levels */
prop = of_find_property(node, "brightness-levels", &length);
if (!prop)
@@ -153,14 +160,13 @@ static int pwm_backlight_parse_dt(struct device_d *dev,
if (pwm_backlight->levels[i] > pwm_backlight->scale)
pwm_backlight->scale = pwm_backlight->levels[i];
- ret = of_property_read_u32(node, "default-brightness-level",
- &value);
- if (ret < 0)
- return ret;
-
- pwm_backlight->backlight.brightness_default = value;
- pwm_backlight->backlight.brightness_max = pwm_backlight->scale;
+ if (pwm_backlight->scale == 0)
+ return -EINVAL;
+ } else {
+ /* We implicitly assume here a linear levels array { 0, 1, 2, ... 100 } */
+ pwm_backlight->scale = 100;
}
+ pwm_backlight->backlight.brightness_max = pwm_backlight->scale;
pwm_backlight->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0, &flags);