diff options
author | Jean Delvare <jdelvare@suse.de> | 2020-08-25 10:20:37 +0300 |
---|---|---|
committer | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2020-08-25 18:50:15 +0300 |
commit | 99363d1c26c825055f8a879d9d5c2b78168cf655 (patch) | |
tree | 19c017e3ef337a348e4c271744b7386ef5b1de82 /drivers/misc/eeprom/at24.c | |
parent | a4423cedc56fd16405240243bdfe6d02823cb26a (diff) | |
download | linux-99363d1c26c825055f8a879d9d5c2b78168cf655.tar.xz |
eeprom: at24: Tidy at24_read()
The elegant code in at24_read() has the drawback that we now need
to make a copy of all parameters to pass them to the post-processing
callback function if there is one. Rewrite the loop in such a way that
the parameters are not modified, so saving them is no longer needed.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Diffstat (limited to 'drivers/misc/eeprom/at24.c')
-rw-r--r-- | drivers/misc/eeprom/at24.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index fb0b8375d5ae..8f5de5f10bbe 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -422,10 +422,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) struct at24_data *at24; struct device *dev; char *buf = val; - int ret; - unsigned int orig_off = off; - char *orig_buf = buf; - size_t orig_count = count; + int i, ret; at24 = priv; dev = at24_base_client_dev(at24); @@ -448,16 +445,13 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) */ mutex_lock(&at24->lock); - while (count) { - ret = at24_regmap_read(at24, buf, off, count); + for (i = 0; count; i += ret, count -= ret) { + ret = at24_regmap_read(at24, buf + i, off + i, count); if (ret < 0) { mutex_unlock(&at24->lock); pm_runtime_put(dev); return ret; } - buf += ret; - off += ret; - count -= ret; } mutex_unlock(&at24->lock); @@ -465,7 +459,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) pm_runtime_put(dev); if (unlikely(at24->read_post)) - at24->read_post(orig_off, orig_buf, orig_count); + at24->read_post(off, buf, i); return 0; } |