mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vladimir Zapolskiy <vz@mleia.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 7/8] misc: eeprom: at25: move eeprom boundary checks to mem_read/mem_write
Date: Mon, 27 Jul 2015 00:18:52 +0300	[thread overview]
Message-ID: <1437945533-27996-7-git-send-email-vz@mleia.com> (raw)
In-Reply-To: <1437945502-27944-1-git-send-email-vz@mleia.com>

The sanity checks for overflow over eeprom size are not needed, if
eeprom is accessed from userspace over sysfs interface, because this
is handled by fs/sysfs/file.c, however in case of reading or writing
within the kernel it might be still reasonable to pass the check.

The change moves these checks from shared at25_ee_read() and
at25_ee_write() directly to at25_mem_read() and at25_mem_write(), no
functional change.

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 drivers/misc/eeprom/at25.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 0a1af93..c4f5c4a 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -77,13 +77,6 @@ at25_ee_read(
 	struct spi_message	m;
 	u8			instr;
 
-	if (unlikely(offset >= at25->bin.size))
-		return 0;
-	if ((offset + count) > at25->bin.size)
-		count = at25->bin.size - offset;
-	if (unlikely(!count))
-		return count;
-
 	cp = command;
 
 	instr = AT25_READ;
@@ -155,13 +148,6 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
 	unsigned		buf_size;
 	u8			*bounce;
 
-	if (unlikely(off >= at25->bin.size))
-		return -EFBIG;
-	if ((off + count) > at25->bin.size)
-		count = at25->bin.size - off;
-	if (unlikely(!count))
-		return count;
-
 	/* Temp buffer starts with command and address */
 	buf_size = at25->chip.page_size;
 	if (buf_size > io_limit)
@@ -288,6 +274,13 @@ static ssize_t at25_mem_read(struct memory_accessor *mem, char *buf,
 {
 	struct at25_data *at25 = container_of(mem, struct at25_data, mem);
 
+	if (unlikely(offset >= at25->bin.size))
+		return 0;
+	if ((offset + count) > at25->bin.size)
+		count = at25->bin.size - offset;
+	if (unlikely(!count))
+		return count;
+
 	return at25_ee_read(at25, buf, offset, count);
 }
 
@@ -296,7 +289,13 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf,
 {
 	struct at25_data *at25 = container_of(mem, struct at25_data, mem);
 
+	if (unlikely(offset >= at25->bin.size))
+		return -EFBIG;
+	if ((offset + count) > at25->bin.size)
+		count = at25->bin.size - offset;
+	if (unlikely(!count))
+		return count;
+
 	return at25_ee_write(at25, buf, offset, count);
 }
 
-- 
2.1.4


  parent reply	other threads:[~2015-07-26 21:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-26 21:18 [PATCH 0/8] misc: remove boundary checks from bin attr users Vladimir Zapolskiy
2015-07-26 21:18 ` [PATCH 1/8] misc: cxl: clean up afu_read_config() Vladimir Zapolskiy
2015-07-26 23:06   ` Daniel Axtens
2015-08-05  7:48   ` Michael Neuling
2015-07-26 21:18 ` [PATCH 2/8] misc: ds1682: clean up ds1682_eeprom_read() and ds1682_eeprom_write() Vladimir Zapolskiy
2015-07-26 21:18 ` [PATCH 3/8] misc: eeprom: 93xx46: clean up eeprom_93xx46_bin_read/write Vladimir Zapolskiy
2015-07-26 21:18 ` [PATCH 4/8] misc: eeprom: clean up eeprom_read() Vladimir Zapolskiy
2015-07-29  7:14   ` Jean Delvare
2015-07-26 21:18 ` [PATCH 5/8] misc: eeprom: max6875: clean up max6875_read() Vladimir Zapolskiy
2015-07-26 21:18 ` [PATCH 6/8] misc: eeprom: at24: clean up at24_bin_write() Vladimir Zapolskiy
2015-07-28  6:11   ` Wolfram Sang
2015-07-26 21:18 ` Vladimir Zapolskiy [this message]
2015-07-26 21:18 ` [PATCH 8/8] misc: eeprom: sunxi_sid: clean up sid_read() Vladimir Zapolskiy
2015-08-07 16:10 ` [PATCH 0/8] misc: remove boundary checks from bin attr users Wolfram Sang
2015-08-07 16:15   ` Vladimir Zapolskiy
2015-08-07 22:34     ` Wolfram Sang
2015-08-08 12:51       ` Vladimir Zapolskiy
2015-08-08 16:49         ` Wolfram Sang

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=1437945533-27996-7-git-send-email-vz@mleia.com \
    --to=vz@mleia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®