lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c183afe8986d444a8e777ae0b9bb9189@AcuMS.aculab.com>
Date: Sun, 29 Sep 2024 21:34:05 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Ricardo Ribalda' <ribalda@...omium.org>, Benoit Parrot <bparrot@...com>,
	Mauro Carvalho Chehab <mchehab@...nel.org>, Sakari Ailus
	<sakari.ailus@...ux.intel.com>, Bingbu Cao <bingbu.cao@...el.com>, "Tianshu
 Qiu" <tian.shu.qiu@...el.com>, Greg Kroah-Hartman
	<gregkh@...uxfoundation.org>, Hans de Goede <hdegoede@...hat.com>, "Andy
 Shevchenko" <andy@...nel.org>, Hans Verkuil <hverkuil-cisco@...all.nl>
CC: "linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"linux-staging@...ts.linux.dev" <linux-staging@...ts.linux.dev>
Subject: RE: [PATCH 3/3] media: atomisp: Use max() macros

From: Ricardo Ribalda
> Sent: 27 September 2024 10:42
> 
> The max() macro produce nicer code and also fixes the following cocci
> errors:
> 
> drivers/staging/media/atomisp/pci/sh_css_frac.h:40:17-18: WARNING opportunity for max()
> drivers/staging/media/atomisp/pci/sh_css_frac.h:50:17-18: WARNING opportunity for max()
> 
> Signed-off-by: Ricardo Ribalda <ribalda@...omium.org>
> ---
>  drivers/staging/media/atomisp/pci/sh_css_frac.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/sh_css_frac.h
> b/drivers/staging/media/atomisp/pci/sh_css_frac.h
> index 8ba65161f7a9..9642506d2388 100644
> --- a/drivers/staging/media/atomisp/pci/sh_css_frac.h
> +++ b/drivers/staging/media/atomisp/pci/sh_css_frac.h
> @@ -37,7 +37,7 @@ static inline int sDIGIT_FITTING(int v, int a, int b)
>  	int fit_shift = sFRACTION_BITS_FITTING(a) - b;
> 
>  	v >>= sSHIFT;

IIRC right shifts of signed values are undefined.
(C does not require a cpu to have a right shift that replicates the
sign bit.)

> -	v >>= fit_shift > 0 ? fit_shift : 0;
> +	v >>= max(fit_shift, 0);

If the shift isn't done the return value is garbage.
So the code better not let it happen.
In which case you might as well let the cpu generate a (different)
random value - so delete the conditional.

> 
>  	return clamp_t(int, v, sISP_VAL_MIN, sISP_VAL_MAX);

all three values seem to be 'int' - so no need for the _t variant
and all the associated casts.

>  }
> @@ -47,7 +47,7 @@ static inline unsigned int uDIGIT_FITTING(unsigned int v, int a, int b)
>  	int fit_shift = uFRACTION_BITS_FITTING(a) - b;
> 
>  	v >>= uSHIFT;
> -	v >>= fit_shift > 0 ? fit_shift : 0;
> +	v >>= max(fit_shift, 0);
> 
>  	return clamp_t(unsigned int, v, uISP_VAL_MIN, uISP_VAL_MAX);

as above, but it is just min(v, iISP_VAL_MAX)

	David

>  }
> 
> --
> 2.46.1.824.gd892dcdcdd-goog
> 

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ