From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0116.outbound.protection.outlook.com ([104.47.33.116]:50578 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1031865AbeCAPYX (ORCPT ); Thu, 1 Mar 2018 10:24:23 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Derek Basehore , Lee Jones , Sasha Levin Subject: [added to the 4.1 stable tree] backlight: pwm_bl: Fix overflow condition Date: Thu, 1 Mar 2018 15:22:53 +0000 Message-ID: <20180301152116.1486-44-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Derek Basehore This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 5d0c49acebc9488e37db95f1d4a55644e545ffe7 ] 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 Signed-off-by: Sasha Levin --- drivers/video/backlight/pwm_bl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm= _bl.c index 6897f1c1bc73..95d01562ffa2 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 =3D pb->lth_brightness; - int duty_cycle; + u64 duty_cycle; =20 if (pb->levels) duty_cycle =3D pb->levels[brightness]; else duty_cycle =3D brightness; =20 - return (duty_cycle * (pb->period - lth) / pb->scale) + lth; + duty_cycle *=3D pb->period - lth; + do_div(duty_cycle, pb->scale); + + return duty_cycle + lth; } =20 static int pwm_backlight_update_status(struct backlight_device *bl) --=20 2.14.1