Simplify functions at24_read/write a little. Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx> --- drivers/misc/eeprom/at24.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index d56be71f1..837f1d88c 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -374,24 +374,20 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) mutex_lock(&at24->lock); while (count) { - int status; + ret = at24_regmap_read(at24, buf, off, count); + if (ret < 0) + goto out; - status = at24_regmap_read(at24, buf, off, count); - if (status < 0) { - mutex_unlock(&at24->lock); - pm_runtime_put(&client->dev); - return status; - } - buf += status; - off += status; - count -= status; + buf += ret; + off += ret; + count -= ret; } - +out: mutex_unlock(&at24->lock); pm_runtime_put(&client->dev); - return 0; + return ret < 0 ? ret : 0; } static int at24_write(void *priv, unsigned int off, void *val, size_t count) @@ -424,24 +420,20 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) mutex_lock(&at24->lock); while (count) { - int status; + ret = at24_regmap_write(at24, buf, off, count); + if (ret < 0) + goto out; - status = at24_regmap_write(at24, buf, off, count); - if (status < 0) { - mutex_unlock(&at24->lock); - pm_runtime_put(&client->dev); - return status; - } - buf += status; - off += status; - count -= status; + buf += ret; + off += ret; + count -= ret; } - +out: mutex_unlock(&at24->lock); pm_runtime_put(&client->dev); - return 0; + return ret < 0 ? ret : 0; } static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip) -- 2.15.0