linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH 09/13] eeprom: ee1004: Factor out setting page to ee1004_set_current_page
Date: Mon, 24 May 2021 22:15:26 +0200	[thread overview]
Message-ID: <21e0966f-e6c9-045f-b130-bd9fb071f0d7@gmail.com> (raw)
In-Reply-To: <bd8439bc-3a6f-fd52-5fd1-bf9782061612@gmail.com>

Factor out setting the page, this makes the code better readable.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/misc/eeprom/ee1004.c | 52 +++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/drivers/misc/eeprom/ee1004.c b/drivers/misc/eeprom/ee1004.c
index d7c693b26..33855e459 100644
--- a/drivers/misc/eeprom/ee1004.c
+++ b/drivers/misc/eeprom/ee1004.c
@@ -71,6 +71,32 @@ static int ee1004_get_current_page(void)
 	return 0;
 }
 
+static int ee1004_set_current_page(struct device *dev, int page)
+{
+	int ret;
+
+	if (page == ee1004_current_page)
+		return 0;
+
+	/* Data is ignored */
+	ret = i2c_smbus_write_byte(ee1004_set_page[page], 0x00);
+	/*
+	 * Don't give up just yet. Some memory modules will select the page
+	 * but not ack the command. Check which page is selected now.
+	 */
+	if (ret == -ENXIO && ee1004_get_current_page() == page)
+		ret = 0;
+	if (ret < 0) {
+		dev_err(dev, "Failed to select page %d (%d)\n", page, ret);
+		return ret;
+	}
+
+	dev_dbg(dev, "Selected page %d\n", page);
+	ee1004_current_page = page;
+
+	return 0;
+}
+
 static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,
 				  unsigned int offset, size_t count)
 {
@@ -110,28 +136,10 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
 		int status;
 
 		/* Select page */
-		if (page != ee1004_current_page) {
-			/* Data is ignored */
-			status = i2c_smbus_write_byte(ee1004_set_page[page],
-						      0x00);
-			if (status == -ENXIO) {
-				/*
-				 * Don't give up just yet. Some memory
-				 * modules will select the page but not
-				 * ack the command. Check which page is
-				 * selected now.
-				 */
-				if (ee1004_get_current_page() == page)
-					status = 0;
-			}
-			if (status < 0) {
-				dev_err(dev, "Failed to select page %d (%d)\n",
-					page, status);
-				mutex_unlock(&ee1004_bus_lock);
-				return status;
-			}
-			dev_dbg(dev, "Selected page %d\n", page);
-			ee1004_current_page = page;
+		status = ee1004_set_current_page(dev, page);
+		if (status) {
+			mutex_unlock(&ee1004_bus_lock);
+			return status;
 		}
 
 		status = ee1004_eeprom_read(client, buf, off, count);
-- 
2.31.1



  parent reply	other threads:[~2021-05-24 20:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 20:08 [PATCH 00/13] eeprom: ee1004: improvements Heiner Kallweit
2021-05-24 20:08 ` [PATCH 01/13] eeprom: ee1004: Use kobj_to_i2c_client to simplify the code Heiner Kallweit
2021-05-24 20:09 ` [PATCH 02/13] eeprom: ee1004: Remove not needed check in ee1004_read Heiner Kallweit
2021-05-24 20:10 ` [PATCH 03/13] eeprom: ee1004: Remove not needed check in ee1004_eeprom_read Heiner Kallweit
2021-05-24 20:11 ` [PATCH 04/13] eeprom: ee1004: Remove usage of i2c_adapter_id in adapter comparison Heiner Kallweit
2021-05-24 20:12 ` [PATCH 05/13] eeprom: ee1004: Improve check for SMBUS features Heiner Kallweit
2021-05-24 20:13 ` [PATCH 06/13] eeprom: ee1004: Improve creating dummy devices Heiner Kallweit
2021-05-24 20:13 ` [PATCH 07/13] eeprom: ee1004: Switch to i2c probe_new callback Heiner Kallweit
2021-05-24 20:14 ` [PATCH 08/13] eeprom: ee1004: Cache current page at initialization of first device only Heiner Kallweit
2021-05-24 20:15 ` Heiner Kallweit [this message]
2021-05-24 20:16 ` [PATCH 10/13] eeprom: ee1004: Improve error handling in ee1004_read Heiner Kallweit
2021-05-24 20:16 ` [PATCH 11/13] eeprom: ee1004: Move call to ee1004_set_current_page to ee1004_eeprom_read Heiner Kallweit
2021-05-24 20:17 ` [PATCH 12/13] eeprom: ee1004: Add constant EE1004_NUM_PAGES Heiner Kallweit
2021-05-24 20:18 ` [PATCH 13/13] eeprom: ee1004: Add helper ee1004_cleanup Heiner Kallweit

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=21e0966f-e6c9-045f-b130-bd9fb071f0d7@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=arnd@arndb.de \
    --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;
as well as URLs for NNTP newsgroup(s).