summaryrefslogtreecommitdiff
path: root/drivers/misc/eeprom
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2021-05-24 23:16:05 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-05-27 15:49:39 +0300
commit6f68dbd6cc7b440c91aea894e214a7065f5fbbb6 (patch)
tree93bd0a60bebdfadb1e253c8eee0e0593b4a613db /drivers/misc/eeprom
parent6601017e2a4936a93c7d9527cd25a4a2c16cc5ef (diff)
downloadlinux-6f68dbd6cc7b440c91aea894e214a7065f5fbbb6.tar.xz
eeprom: ee1004: Improve error handling in ee1004_read
Simplify the error handling and make it better readable. No functional change intended. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Link: https://lore.kernel.org/r/13ad7b39-e722-d70a-e25b-03d1fb1734a7@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/eeprom')
-rw-r--r--drivers/misc/eeprom/ee1004.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/drivers/misc/eeprom/ee1004.c b/drivers/misc/eeprom/ee1004.c
index 33855e459a40..d18348ee4a57 100644
--- a/drivers/misc/eeprom/ee1004.c
+++ b/drivers/misc/eeprom/ee1004.c
@@ -119,7 +119,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;
+ int page, ret = 0;
page = off >> EE1004_PAGE_SHIFT;
if (unlikely(page > 1))
@@ -133,33 +133,28 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
mutex_lock(&ee1004_bus_lock);
while (count) {
- int status;
-
/* Select page */
- status = ee1004_set_current_page(dev, page);
- if (status) {
- mutex_unlock(&ee1004_bus_lock);
- return status;
- }
+ ret = ee1004_set_current_page(dev, page);
+ if (ret)
+ goto out;
- status = ee1004_eeprom_read(client, buf, off, count);
- if (status < 0) {
- mutex_unlock(&ee1004_bus_lock);
- return status;
- }
- buf += status;
- off += status;
- count -= status;
+ ret = ee1004_eeprom_read(client, buf, off, count);
+ if (ret < 0)
+ goto out;
+
+ buf += ret;
+ off += ret;
+ count -= ret;
if (off == EE1004_PAGE_SIZE) {
page++;
off = 0;
}
}
-
+out:
mutex_unlock(&ee1004_bus_lock);
- return requested;
+ return ret < 0 ? ret : requested;
}
static BIN_ATTR_RO(eeprom, EE1004_EEPROM_SIZE);