From: Daniel Thompson <daniel.thompson@linaro.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-clk@vger.kernel.org
Subject: Re: clk: stm32: Add clock driver for STM32F4[23]xxx devices
Date: Fri, 26 Jun 2015 11:53:33 +0100 [thread overview]
Message-ID: <558D2F2D.4020803@linaro.org> (raw)
In-Reply-To: <20150626103110.GA350@mwanda>
On 26/06/15 11:31, Dan Carpenter wrote:
> Hello Daniel Thompson,
>
> The patch 358bdf892f6b: "clk: stm32: Add clock driver for
> STM32F4[23]xxx devices" from Jun 10, 2015, leads to the following
> static checker warning:
>
> drivers/clk/clk-stm32f4.c:271 stm32f4_rcc_lookup_clk_idx()
> warn: buffer overflow 'table' 3 <= 3
>
> drivers/clk/clk-stm32f4.c
> 258 static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary)
> 259 {
> 260 u64 table[ARRAY_SIZE(stm32f42xx_gate_map)];
> 261
> 262 if (primary == 1) {
> 263 if (WARN_ON(secondary > FCLK))
>
> Is this off by one? >= instead of >?
This one is ok (FCLK is a valid value for secondary when primary is 1).
> 264 return -EINVAL;
> 265 return secondary;
> 266 }
> 267
> 268 memcpy(table, stm32f42xx_gate_map, sizeof(table));
> 269
> 270 /* only bits set in table can be used as indices */
> 271 if (WARN_ON(secondary > 8 * sizeof(table) ||
>
> This one is definitely off by one.
Agreed.
> Also it might be easier to read as:
> if (WARN_ON(secondary >= 64 * ARRAY_SIZE(table) ||
I guess the thing we want to be clear is that we are comparing against
the number of bits in table.
Maybe just "BITS_PER_BYTE * sizeof(table)" achieves that best?
BTW... you're happy for me to send a patch on this (with a Reported-by:)?
Daniel.
next prev parent reply other threads:[~2015-06-26 10:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-26 10:31 clk: stm32: Add clock driver for STM32F4[23]xxx devices Dan Carpenter
2015-06-26 10:53 ` Daniel Thompson [this message]
2015-06-26 10:56 ` Dan Carpenter
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=558D2F2D.4020803@linaro.org \
--to=daniel.thompson@linaro.org \
--cc=dan.carpenter@oracle.com \
--cc=linux-clk@vger.kernel.org \
/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.