public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: daniel.thompson@linaro.org
Cc: linux-clk@vger.kernel.org
Subject: re: clk: stm32: Add clock driver for STM32F4[23]xxx devices
Date: Fri, 26 Jun 2015 13:31:10 +0300	[thread overview]
Message-ID: <20150626103110.GA350@mwanda> (raw)

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 >?

   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.  Also it might be easier to read as:

		if (WARN_ON(secondary >= 64 * ARRAY_SIZE(table) ||

   272                      0 == (table[BIT_ULL_WORD(secondary)] &
   273                            BIT_ULL_MASK(secondary))))
   274                  return -EINVAL;
   275  
   276          /* mask out bits above our current index */
   277          table[BIT_ULL_WORD(secondary)] &=
   278              GENMASK_ULL(secondary % BITS_PER_LONG_LONG, 0);
   279  
   280          return FCLK + hweight64(table[0]) +
   281                 (BIT_ULL_WORD(secondary) >= 1 ? hweight64(table[1]) : 0) +
   282                 (BIT_ULL_WORD(secondary) >= 2 ? hweight64(table[2]) : 0);
   283  }

regards,
dan carpenter

             reply	other threads:[~2015-06-26 10:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 10:31 Dan Carpenter [this message]
2015-06-26 10:53 ` clk: stm32: Add clock driver for STM32F4[23]xxx devices Daniel Thompson
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=20150626103110.GA350@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=daniel.thompson@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox