[2/2] hwmon: (oxp-sensors) Simplify logic of error return

Message ID 20230617181159.32844-3-samsagax@gmail.com
State New
Headers
Series hwmon: (oxp-sensors) Minor cleanup of driver code |

Commit Message

Joaquín Ignacio Aramendía June 17, 2023, 6:11 p.m. UTC
  Take return logic on error out of if-else, eliminating
duplicated code in tt_togle_store() function.

Signed-off-by: Joaquín Ignacio Aramendía <samsagax@gmail.com>
---
 drivers/hwmon/oxp-sensors.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
  

Comments

Guenter Roeck June 18, 2023, 3:54 p.m. UTC | #1
On Sat, Jun 17, 2023 at 03:11:43PM -0300, Joaquín Ignacio Aramendía wrote:
> Take return logic on error out of if-else, eliminating
> duplicated code in tt_togle_store() function.
> 
> Signed-off-by: Joaquín Ignacio Aramendía <samsagax@gmail.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/oxp-sensors.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
> index 584e48d8106e..1e59d97219c4 100644
> --- a/drivers/hwmon/oxp-sensors.c
> +++ b/drivers/hwmon/oxp-sensors.c
> @@ -226,13 +226,12 @@ static ssize_t tt_toggle_store(struct device *dev,
>  
>  	if (value) {
>  		rval = tt_toggle_enable();
> -		if (rval)
> -			return rval;
>  	} else {
>  		rval = tt_toggle_disable();
> -		if (rval)
> -			return rval;
>  	}
> +	if (rval)
> +		return rval;
> +
>  	return count;
>  }
>
  

Patch

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index 584e48d8106e..1e59d97219c4 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -226,13 +226,12 @@  static ssize_t tt_toggle_store(struct device *dev,
 
 	if (value) {
 		rval = tt_toggle_enable();
-		if (rval)
-			return rval;
 	} else {
 		rval = tt_toggle_disable();
-		if (rval)
-			return rval;
 	}
+	if (rval)
+		return rval;
+
 	return count;
 }