Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755610AbbGZV3O (ORCPT ); Sun, 26 Jul 2015 17:29:14 -0400 Received: from li271-223.members.linode.com ([178.79.152.223]:55691 "EHLO mail.mleia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755293AbbGZV0D (ORCPT ); Sun, 26 Jul 2015 17:26:03 -0400 From: Vladimir Zapolskiy To: Greg Kroah-Hartman 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 Message-Id: <1437945533-27996-7-git-send-email-vz@mleia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437945502-27944-1-git-send-email-vz@mleia.com> References: <1437945502-27944-1-git-send-email-vz@mleia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-49551924 X-CRM114-CacheID: sfid-20150726_222436_884938_61FCACFF X-CRM114-Status: GOOD ( 15.44 ) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2509 Lines: 82 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/