Skip to content

Commit

Permalink
eeprom: at24: check at24_read/write arguments
Browse files Browse the repository at this point in the history
So far we completely rely on the caller to provide valid arguments.
To be on the safe side perform an own sanity check.

Cc: stable@vger.kernel.org
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
  • Loading branch information
Heiner Kallweit authored and Bartosz Golaszewski committed Nov 29, 2017
1 parent 644a1f1 commit d9bcd46
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/misc/eeprom/at24.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
if (unlikely(!count))
return count;

if (off + count > at24->chip.byte_len)
return -EINVAL;

client = at24_translate_offset(at24, &off);

ret = pm_runtime_get_sync(&client->dev);
Expand Down Expand Up @@ -614,6 +617,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
if (unlikely(!count))
return -EINVAL;

if (off + count > at24->chip.byte_len)
return -EINVAL;

client = at24_translate_offset(at24, &off);

ret = pm_runtime_get_sync(&client->dev);
Expand Down

0 comments on commit d9bcd46

Please sign in to comment.