aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2017-11-24 01:47:50 -0500
committerBartosz Golaszewski <brgl@bgdev.pl>2017-11-29 10:05:37 -0500
commitd9bcd462daf34aebb8de9ad7f76de0198bb5a0f0 (patch)
treeb80337dac5851c6c59cfddd321e3b447277fdec1
parent644a1f19c6c8393d0c4168a5adf79056da6822eb (diff)
eeprom: at24: check at24_read/write arguments
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>
-rw-r--r--drivers/misc/eeprom/at24.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 8ca6772b3baf..305a7a464d09 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -569,6 +569,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
569 if (unlikely(!count)) 569 if (unlikely(!count))
570 return count; 570 return count;
571 571
572 if (off + count > at24->chip.byte_len)
573 return -EINVAL;
574
572 client = at24_translate_offset(at24, &off); 575 client = at24_translate_offset(at24, &off);
573 576
574 ret = pm_runtime_get_sync(&client->dev); 577 ret = pm_runtime_get_sync(&client->dev);
@@ -614,6 +617,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
614 if (unlikely(!count)) 617 if (unlikely(!count))
615 return -EINVAL; 618 return -EINVAL;
616 619
620 if (off + count > at24->chip.byte_len)
621 return -EINVAL;
622
617 client = at24_translate_offset(at24, &off); 623 client = at24_translate_offset(at24, &off);
618 624
619 ret = pm_runtime_get_sync(&client->dev); 625 ret = pm_runtime_get_sync(&client->dev);