linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: comedi: replace ternary operator with min()
@ 2022-05-13  7:16 Guo Zhengkui
  2022-05-13  9:58 ` Ian Abbott
  0 siblings, 1 reply; 2+ messages in thread
From: Guo Zhengkui @ 2022-05-13  7:16 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, Guo Zhengkui,
	open list
  Cc: zhengkui_guo

Fix the following coccicheck warning:

drivers/comedi/drivers.c:857:12-13: WARNING opportunity for min().

min() macro is defined in include/linux/minmax.h. It avoids multiple
evaluations of the arguments when non-constant and performs strict
type-checking.

Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
 drivers/comedi/drivers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/comedi/drivers.c b/drivers/comedi/drivers.c
index 8eb1f699a857..d4e2ed709bfc 100644
--- a/drivers/comedi/drivers.c
+++ b/drivers/comedi/drivers.c
@@ -854,7 +854,7 @@ int comedi_load_firmware(struct comedi_device *dev,
 		release_firmware(fw);
 	}
 
-	return ret < 0 ? ret : 0;
+	return min(ret, 0);
 }
 EXPORT_SYMBOL_GPL(comedi_load_firmware);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers: comedi: replace ternary operator with min()
  2022-05-13  7:16 [PATCH] drivers: comedi: replace ternary operator with min() Guo Zhengkui
@ 2022-05-13  9:58 ` Ian Abbott
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Abbott @ 2022-05-13  9:58 UTC (permalink / raw)
  To: Guo Zhengkui, H Hartley Sweeten, Greg Kroah-Hartman, open list
  Cc: zhengkui_guo

On 13/05/2022 08:16, Guo Zhengkui wrote:
> Fix the following coccicheck warning:
> 
> drivers/comedi/drivers.c:857:12-13: WARNING opportunity for min().
> 
> min() macro is defined in include/linux/minmax.h. It avoids multiple
> evaluations of the arguments when non-constant and performs strict
> type-checking.
> 
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
> ---
>   drivers/comedi/drivers.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/comedi/drivers.c b/drivers/comedi/drivers.c
> index 8eb1f699a857..d4e2ed709bfc 100644
> --- a/drivers/comedi/drivers.c
> +++ b/drivers/comedi/drivers.c
> @@ -854,7 +854,7 @@ int comedi_load_firmware(struct comedi_device *dev,
>   		release_firmware(fw);
>   	}
>   
> -	return ret < 0 ? ret : 0;
> +	return min(ret, 0);
>   }
>   EXPORT_SYMBOL_GPL(comedi_load_firmware);
>   

Looks good thanks.

I was wondering if it could be replaced with a simple `return ret;`, but 
unfortunately the `ret = cb(...);` call returns a non-negative value on 
success for some of the drivers' callback functions.  (The usbdux* 
drivers return the result of a call to `usb_control_msg(...)`.)

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-13 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13  7:16 [PATCH] drivers: comedi: replace ternary operator with min() Guo Zhengkui
2022-05-13  9:58 ` Ian Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).