From 70f989db308ca23b47b09ee92232533e84a636fb Mon Sep 17 00:00:00 2001 From: Willie Ruan Date: Tue, 10 Jan 2012 10:09:36 -0800 Subject: [PATCH] mfd: pm8xxx-pwm: fix an overflow bug The overflow could be the multiplication (period_us * NSEC_PER_USEC) in next line, rather than at the 6-bit max period value. So we should use the max unsigned int value as boundary. Change-Id: Ida753d752a8ca144b4c158e1a6ed505077de98ea Signed-off-by: Willie Ruan --- drivers/mfd/pm8xxx-pwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/pm8xxx-pwm.c b/drivers/mfd/pm8xxx-pwm.c index f65a1835112..6ffc7cc6344 100644 --- a/drivers/mfd/pm8xxx-pwm.c +++ b/drivers/mfd/pm8xxx-pwm.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -342,7 +342,7 @@ static void pm8xxx_pwm_calc_period(unsigned int period_us, unsigned int tmp_p, last_p, min_err, period_n; /* PWM Period / N */ - if (period_us < (40 * USEC_PER_SEC)) { /* ~6-bit max */ + if (period_us < ((unsigned)(-1) / NSEC_PER_USEC)) { period_n = (period_us * NSEC_PER_USEC) >> 6; n = 6; } else if (period_us < (274 * USEC_PER_SEC)) { /* overflow threshold */