lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2829a131-51e3-8865-462a-564080158b0b@gmail.com>
Date:   Mon, 24 May 2021 22:16:51 +0200
From:   Heiner Kallweit <hkallweit1@...il.com>
To:     Arnd Bergmann <arnd@...db.de>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: [PATCH 11/13] eeprom: ee1004: Move call to ee1004_set_current_page to
 ee1004_eeprom_read

Moving the call to ee1004_set_current_page() to ee1004_eeprom_read()
allows to simplify the code.

Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
---
 drivers/misc/eeprom/ee1004.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/misc/eeprom/ee1004.c b/drivers/misc/eeprom/ee1004.c
index d18348ee4..65fe11d8f 100644
--- a/drivers/misc/eeprom/ee1004.c
+++ b/drivers/misc/eeprom/ee1004.c
@@ -100,7 +100,14 @@ static int ee1004_set_current_page(struct device *dev, int page)
 static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,
 				  unsigned int offset, size_t count)
 {
-	int status;
+	int status, page;
+
+	page = offset >> EE1004_PAGE_SHIFT;
+	offset &= (1 << EE1004_PAGE_SHIFT) - 1;
+
+	status = ee1004_set_current_page(&client->dev, page);
+	if (status)
+		return status;
 
 	/* Can't cross page boundaries */
 	if (offset + count > EE1004_PAGE_SIZE)
@@ -119,12 +126,7 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
 {
 	struct i2c_client *client = kobj_to_i2c_client(kobj);
 	size_t requested = count;
-	int page, ret = 0;
-
-	page = off >> EE1004_PAGE_SHIFT;
-	if (unlikely(page > 1))
-		return 0;
-	off &= (1 << EE1004_PAGE_SHIFT) - 1;
+	int ret = 0;
 
 	/*
 	 * Read data from chip, protecting against concurrent access to
@@ -133,11 +135,6 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
 	mutex_lock(&ee1004_bus_lock);
 
 	while (count) {
-		/* Select page */
-		ret = ee1004_set_current_page(dev, page);
-		if (ret)
-			goto out;
-
 		ret = ee1004_eeprom_read(client, buf, off, count);
 		if (ret < 0)
 			goto out;
@@ -145,11 +142,6 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
 		buf += ret;
 		off += ret;
 		count -= ret;
-
-		if (off == EE1004_PAGE_SIZE) {
-			page++;
-			off = 0;
-		}
 	}
 out:
 	mutex_unlock(&ee1004_bus_lock);
-- 
2.31.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ