From 5d0c49acebc9488e37db95f1d4a55644e545ffe7 Mon Sep 17 00:00:00 2001 From: Derek Basehore Date: Tue, 29 Aug 2017 13:34:34 -0700 Subject: backlight: pwm_bl: Fix overflow condition This fixes an overflow condition that can happen with high max brightness and period values in compute_duty_cycle. This fixes it by using a 64 bit variable for computing the duty cycle. Signed-off-by: Derek Basehore Acked-by: Thierry Reding Reviewed-by: Brian Norris Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 9bd17682655a..1c2289ddd555 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -79,14 +79,17 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) { unsigned int lth = pb->lth_brightness; - int duty_cycle; + u64 duty_cycle; if (pb->levels) duty_cycle = pb->levels[brightness]; else duty_cycle = brightness; - return (duty_cycle * (pb->period - lth) / pb->scale) + lth; + duty_cycle *= pb->period - lth; + do_div(duty_cycle, pb->scale); + + return duty_cycle + lth; } static int pwm_backlight_update_status(struct backlight_device *bl) -- cgit v1.2.3 From 5158cc2d4eca66c1c5ef1939d8fa02942f532515 Mon Sep 17 00:00:00 2001 From: Christos Gkekas Date: Sun, 8 Oct 2017 22:56:48 +0100 Subject: backlight: tps65217_bl: Remove unnecessary default brightness check Variable val holds the default brightness and is unsigned, therefore checking whether it is less than zero is redundant. Signed-off-by: Christos Gkekas Acked-by: Daniel Thompson Acked-by: Jingoo Han Signed-off-by: Lee Jones --- drivers/video/backlight/tps65217_bl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/tps65217_bl.c b/drivers/video/backlight/tps65217_bl.c index fd524ad860a5..61ea82d2abf4 100644 --- a/drivers/video/backlight/tps65217_bl.c +++ b/drivers/video/backlight/tps65217_bl.c @@ -239,8 +239,7 @@ tps65217_bl_parse_dt(struct platform_device *pdev) } if (!of_property_read_u32(node, "default-brightness", &val)) { - if (val < 0 || - val > 100) { + if (val > 100) { dev_err(&pdev->dev, "invalid 'default-brightness' value in the device tree\n"); err = ERR_PTR(-EINVAL); -- cgit v1.2.3 From 29fae2c1db242a39c5c7c49434fb183f990df2f8 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Sun, 5 Nov 2017 11:53:26 +0000 Subject: backlight: ili922x: Remove redundant variable len The variable len is assigned but never read, therefore it is redundant and can be removed. Cleans up clang warning: drivers/video/backlight/ili922x.c:276:2: warning: Value stored to 'len' is never read Signed-off-by: Colin Ian King Acked-by: Daniel Thompson Acked-by: Jingoo Han Signed-off-by: Lee Jones --- drivers/video/backlight/ili922x.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/ili922x.c b/drivers/video/backlight/ili922x.c index a9e9cef20ed6..2b6c6aaf4e14 100644 --- a/drivers/video/backlight/ili922x.c +++ b/drivers/video/backlight/ili922x.c @@ -251,7 +251,7 @@ static int ili922x_write(struct spi_device *spi, u8 reg, u16 value) struct spi_transfer xfer_regindex, xfer_regvalue; unsigned char tbuf[CMD_BUFSIZE]; unsigned char rbuf[CMD_BUFSIZE]; - int ret, len = 0; + int ret; memset(&xfer_regindex, 0, sizeof(struct spi_transfer)); memset(&xfer_regvalue, 0, sizeof(struct spi_transfer)); @@ -273,7 +273,6 @@ static int ili922x_write(struct spi_device *spi, u8 reg, u16 value) ret = spi_sync(spi, &msg); spi_message_init(&msg); - len = 0; tbuf[0] = set_tx_byte(START_BYTE(ili922x_id, START_RS_REG, START_RW_WRITE)); tbuf[1] = set_tx_byte((value & 0xFF00) >> 8); -- cgit v1.2.3