diff mbox series

[4/7] eeprom: at24: simplify functions at24_read/write a little

Message ID 1b2f8ac8-02ae-d615-8c23-6d90f52be555@gmail.com
State Not Applicable
Delegated to: Bartosz Golaszewski
Headers show
Series eeprom: at24: series with smaller improvements | expand

Commit Message

Heiner Kallweit Nov. 30, 2017, 6:49 a.m. UTC
Simplify functions at24_read/write a little.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/misc/eeprom/at24.c | 40 ++++++++++++++++------------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

Comments

Bartosz Golaszewski Dec. 1, 2017, 10:14 a.m. UTC | #1
2017-11-30 7:49 GMT+01:00 Heiner Kallweit <hkallweit1@gmail.com>:
> Simplify functions at24_read/write a little.
>

Please be more specific in your commit message - it's not obvious at
first glance what you're actually simplifying.

Thanks,
Bartosz

> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  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
>
>
diff mbox series

Patch

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)