[PATCH] w1: w1_therm: use swap() to make code cleaner

davidcomponentone@gmail.com posted 1 patch 4 years, 6 months ago
There is a newer version of this series
drivers/w1/slaves/w1_therm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] w1: w1_therm: use swap() to make code cleaner
Posted by davidcomponentone@gmail.com 4 years, 6 months ago
From: Yang Guang <yang.guang5@zte.com.cn>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: David Yang <davidcomponentone@gmail.com>
Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
---
 drivers/w1/slaves/w1_therm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index ca70c5f03206..c743cb3d277a 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -1785,7 +1785,7 @@ static ssize_t alarms_store(struct device *device,
 	u8 new_config_register[3];	/* array of data to be written */
 	int temp, ret;
 	char *token = NULL;
-	s8 tl, th, tt;	/* 1 byte per value + temp ring order */
+	s8 tl, th;	/* 1 byte per value + temp ring order */
 	char *p_args, *orig;
 
 	p_args = orig = kmalloc(size, GFP_KERNEL);
@@ -1837,7 +1837,7 @@ static ssize_t alarms_store(struct device *device,
 
 	/* Reorder if required th and tl */
 	if (tl > th) {
-		tt = tl; tl = th; th = tt;
+		swap(tl, th);
 	}
 
 	/*
-- 
2.30.2

Re: [PATCH] w1: w1_therm: use swap() to make code cleaner
Posted by Dan Carpenter 4 years, 6 months ago
On Sat, Dec 18, 2021 at 09:58:44AM +0800, davidcomponentone@gmail.com wrote:
> @@ -1837,7 +1837,7 @@ static ssize_t alarms_store(struct device *device,
>  
>  	/* Reorder if required th and tl */
>  	if (tl > th) {
> -		tt = tl; tl = th; th = tt;
> +		swap(tl, th);
>  	}

Delete the curly {} braces as well since they are no longer required.

regards,
dan carpenter