Skip to content

Commit

Permalink
mfd: Fix error in wm8400 reg cache access check
Browse files Browse the repository at this point in the history
Accessing num_reg elements in the interval [reg .. reg+num_regs)
is permitted if (reg+numregs <= array size), so barf when that
excluded upper bound is > array size. The prior -1 would give
access to one too many elements.

Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Phil Carmody authored and Samuel Ortiz committed May 27, 2010
1 parent da1e368 commit fffba64
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/mfd/wm8400-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest)
{
int i, ret = 0;

BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache));
BUG_ON(reg + num_regs > ARRAY_SIZE(wm8400->reg_cache));

/* If there are any volatile reads then read back the entire block */
for (i = reg; i < reg + num_regs; i++)
Expand All @@ -144,7 +144,7 @@ static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs,
{
int ret, i;

BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache));
BUG_ON(reg + num_regs > ARRAY_SIZE(wm8400->reg_cache));

for (i = 0; i < num_regs; i++) {
BUG_ON(!reg_data[reg + i].writable);
Expand Down

0 comments on commit fffba64

Please sign in to comment.