From: NeilBrown <neilb@suse.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: rpurdie@rpsys.net, linux-kernel@vger.kernel.org
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH 2/2] leds-tca6507 - fix off by one error.
Date: Mon, 19 Dec 2011 11:20:22 +1100 [thread overview]
Message-ID: <20111219002022.23170.29061.stgit@notabene.brown> (raw)
In-Reply-To: <20111219001806.23170.14518.stgit@notabene.brown>
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 <dan.carpenter@oracle.com>
Signed-off-by: NeilBrown <neilb@suse.de>
---
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 c9cc3f7..75dc5e4 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;
next prev parent reply other threads:[~2011-12-19 0:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-19 0:20 [PATCH 0/2] Two fixes for leds-tca6507 NeilBrown
2011-12-19 0:20 ` NeilBrown [this message]
2011-12-19 0:20 ` [PATCH 1/2] leds-tca6507: allow driver to compile when GPIOLIB is not available NeilBrown
2011-12-19 20:34 ` Randy Dunlap
2011-12-20 5:37 ` NeilBrown
-- strict thread matches above, loose matches on Subject: below --
2011-12-20 5:44 [PATCH 0/2] Two fixes for leds-tca6507 - Version 2 NeilBrown
2011-12-20 5:44 ` [PATCH 2/2] leds-tca6507 - fix off by one error NeilBrown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111219002022.23170.29061.stgit@notabene.brown \
--to=neilb@suse.de \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rpurdie@rpsys.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.