From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751248Ab1LTFqt (ORCPT ); Tue, 20 Dec 2011 00:46:49 -0500 Received: from cantor2.suse.de ([195.135.220.15]:34056 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752203Ab1LTFqa (ORCPT ); Tue, 20 Dec 2011 00:46:30 -0500 From: NeilBrown To: Andrew Morton Date: Tue, 20 Dec 2011 16:44:41 +1100 Subject: [PATCH 2/2] leds-tca6507 - fix off by one error. Cc: rpurdie@rpsys.net, linux-kernel@vger.kernel.org Message-ID: <20111220054441.7043.64449.stgit@notabene.brown> In-Reply-To: <20111220054233.7043.3561.stgit@notabene.brown> References: <20111220054233.7043.3561.stgit@notabene.brown> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When walking the list of possible time codes we can fall off the end. Fix that, and also improved the commentary. Reported-by: Dan Carpenter Signed-off-by: NeilBrown --- drivers/leds/leds-tca6507.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c index 3565a61..7680f50 100644 --- a/drivers/leds/leds-tca6507.c +++ b/drivers/leds/leds-tca6507.c @@ -165,7 +165,8 @@ MODULE_DEVICE_TABLE(i2c, tca6507); static int choose_times(int msec, int *c1p, int *c2p) { /* Chose two timecodes which add to 'msec' as near as possible. - * The first returned should be the larger. + * The first returned should be the larger and is the 'on' of 'off' time. + * The second will be used as a 'fade-on' or 'fade-off' time. * If cannot get within 1/8, fail. * If two possibilities are equally good (e.g. 512+0, 256+256), choose * the first pair so there is more change-time visible (i.e. it is softer). @@ -175,7 +176,10 @@ static int choose_times(int msec, int *c1p, int *c2p) int tmin = msec * 7 / 8; int diff = 65536; - for (c1 = 1; c1 <= TIMECODES; c1++) { + /* We start at '1' to ensure we never even think of choosing a + * total time of '0'. + */ + for (c1 = 1; c1 < TIMECODES; c1++) { int t = time_codes[c1]; if (t*2 < tmin) continue;