public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] minmax: allow comparisons of 'long long int' against 'unsigned char/short/int'
@ 2024-01-07 20:11 Matt Jan
  2024-01-07 20:55 ` David Laight
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Jan @ 2024-01-07 20:11 UTC (permalink / raw)
  To: Andrew Morton, David Laight, Andy Shevchenko, Herve Codina,
	Mark Brown, Matt Jan, Matthew Wilcox (Oracle), linux-kernel

Since 'unsigned int' get promoted to 'signed long long int' it is safe
to compare them against an 'long long int' value.

Signed-off-by: Matt Jan <zoo868e@gmail.com>
---
 include/linux/minmax.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 2ec559284a9f..61171286b468 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -37,7 +37,7 @@
 
 #define __types_ok(x, y) 					\
 	(__is_signed(x) == __is_signed(y) ||			\
-		__is_signed((x) + 0) == __is_signed((y) + 0) ||	\
+		__is_signed((x) + 0ll) == __is_signed((y) + 0ll) ||	\
 		__is_noneg_int(x) || __is_noneg_int(y))
 
 #define __cmp_op_min <
-- 
2.34.1


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

* RE: [PATCH] minmax: allow comparisons of 'long long int' against 'unsigned char/short/int'
  2024-01-07 20:11 [PATCH] minmax: allow comparisons of 'long long int' against 'unsigned char/short/int' Matt Jan
@ 2024-01-07 20:55 ` David Laight
  0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2024-01-07 20:55 UTC (permalink / raw)
  To: 'Matt Jan', Andrew Morton, Andy Shevchenko, Herve Codina,
	Mark Brown, Matthew Wilcox (Oracle), linux-kernel@vger.kernel.org

From: Matt Jan
> Sent: 07 January 2024 20:11
> 
> Since 'unsigned int' get promoted to 'signed long long int' it is safe
> to compare them against an 'long long int' value.

Yes, but not as below.
That change would allow pretty much everything through since everything
except 'unsigned long long' would be signed.

You'd need a much more complex check and the CPP bloat is pretty
horrid already.

That particular check is there to promote unsigned char/short to
signed int - which always happens.

	David

> 
> Signed-off-by: Matt Jan <zoo868e@gmail.com>
> ---
>  include/linux/minmax.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/minmax.h b/include/linux/minmax.h
> index 2ec559284a9f..61171286b468 100644
> --- a/include/linux/minmax.h
> +++ b/include/linux/minmax.h
> @@ -37,7 +37,7 @@
> 
>  #define __types_ok(x, y) 					\
>  	(__is_signed(x) == __is_signed(y) ||			\
> -		__is_signed((x) + 0) == __is_signed((y) + 0) ||	\
> +		__is_signed((x) + 0ll) == __is_signed((y) + 0ll) ||	\
>  		__is_noneg_int(x) || __is_noneg_int(y))
> 
>  #define __cmp_op_min <
> --
> 2.34.1
> 

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


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

end of thread, other threads:[~2024-01-07 20:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-07 20:11 [PATCH] minmax: allow comparisons of 'long long int' against 'unsigned char/short/int' Matt Jan
2024-01-07 20:55 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox