platform/x86: dell-smo8800: Use min_t() for comparison and assignment

Message ID Y9P8debIztOZXazW@ubun2204.myguest.virtualbox.org
State New
Headers
Series platform/x86: dell-smo8800: Use min_t() for comparison and assignment |

Commit Message

Deepak R Varma Jan. 27, 2023, 4:31 p.m. UTC
  Simplify code by using min_t helper macro for logical evaluation
and value assignment. Use the _t variant of min macro since the
variable types are not same.
This issue is identified by coccicheck using the minmax.cocci file.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
 drivers/platform/x86/dell/dell-smo8800.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
  

Comments

Pali Rohár Jan. 28, 2023, 2:02 p.m. UTC | #1
On Friday 27 January 2023 22:01:49 Deepak R Varma wrote:
> Simplify code by using min_t helper macro for logical evaluation
> and value assignment. Use the _t variant of min macro since the
> variable types are not same.
> This issue is identified by coccicheck using the minmax.cocci file.
> 
> Signed-off-by: Deepak R Varma <drv@mailo.com>

Looks good,

Acked-by: Pali Rohár <pali@kernel.org>

> ---
>  drivers/platform/x86/dell/dell-smo8800.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c
> index 3385e852104c..8d6b7a83cf24 100644
> --- a/drivers/platform/x86/dell/dell-smo8800.c
> +++ b/drivers/platform/x86/dell/dell-smo8800.c
> @@ -67,10 +67,7 @@ static ssize_t smo8800_misc_read(struct file *file, char __user *buf,
>  
>  	retval = 1;
>  
> -	if (data < 255)
> -		byte_data = data;
> -	else
> -		byte_data = 255;
> +	byte_data = min_t(u32, data, 255);
>  
>  	if (put_user(byte_data, buf))
>  		retval = -EFAULT;
> -- 
> 2.34.1
> 
> 
>
  
Hans de Goede Jan. 30, 2023, 3:36 p.m. UTC | #2
Hi,

On 1/27/23 17:31, Deepak R Varma wrote:
> Simplify code by using min_t helper macro for logical evaluation
> and value assignment. Use the _t variant of min macro since the
> variable types are not same.
> This issue is identified by coccicheck using the minmax.cocci file.
> 
> Signed-off-by: Deepak R Varma <drv@mailo.com>

Thank you for your patch, I've applied this patch to my review-hans 
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans


> ---
>  drivers/platform/x86/dell/dell-smo8800.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c
> index 3385e852104c..8d6b7a83cf24 100644
> --- a/drivers/platform/x86/dell/dell-smo8800.c
> +++ b/drivers/platform/x86/dell/dell-smo8800.c
> @@ -67,10 +67,7 @@ static ssize_t smo8800_misc_read(struct file *file, char __user *buf,
>  
>  	retval = 1;
>  
> -	if (data < 255)
> -		byte_data = data;
> -	else
> -		byte_data = 255;
> +	byte_data = min_t(u32, data, 255);
>  
>  	if (put_user(byte_data, buf))
>  		retval = -EFAULT;
  

Patch

diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c
index 3385e852104c..8d6b7a83cf24 100644
--- a/drivers/platform/x86/dell/dell-smo8800.c
+++ b/drivers/platform/x86/dell/dell-smo8800.c
@@ -67,10 +67,7 @@  static ssize_t smo8800_misc_read(struct file *file, char __user *buf,
 
 	retval = 1;
 
-	if (data < 255)
-		byte_data = data;
-	else
-		byte_data = 255;
+	byte_data = min_t(u32, data, 255);
 
 	if (put_user(byte_data, buf))
 		retval = -EFAULT;