linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant
@ 2023-08-16  8:53 Jiri Slaby (SUSE)
  2023-08-16 11:45 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-08-16  8:53 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Nathan Chancellor,
	kernel test robot

My thinking was that ulong is the same as size_t everywhere. No, size_t
is uint on 32bit. So the below commit introduced a build warning on
32bit:
.../gdm724x/gdm_tty.c:165:24: warning: comparison of distinct pointer types ('typeof (2048UL) *' (aka 'unsigned long *') and 'typeof (remain) *' (aka 'unsigned int *'))

To fix this, partially revert the commit (remove constants' suffixes)
and switch to min_t() in this case instead.

/me would hope for Z (or alike) suffix for constants.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Fixes: c3e5c706aefc (tty: gdm724x: convert counts to size_t)
Reported-by: Nathan Chancellor <nathan@kernel.org>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202308151953.rNNnAR2N-lkp@intel.com/
---
 drivers/staging/gdm724x/gdm_tty.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
index 67d9bf41e836..32b2e817ff04 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -17,9 +17,9 @@
 #define GDM_TTY_MAJOR 0
 #define GDM_TTY_MINOR 32
 
-#define WRITE_SIZE 2048UL
+#define WRITE_SIZE 2048
 
-#define MUX_TX_MAX_SIZE 2048UL
+#define MUX_TX_MAX_SIZE 2048
 
 static inline bool gdm_tty_ready(struct gdm *gdm)
 {
@@ -159,7 +159,7 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
 		return -ENODEV;
 
 	while (remain) {
-		size_t sending_len = min(MUX_TX_MAX_SIZE, remain);
+		size_t sending_len = min_t(size_t, MUX_TX_MAX_SIZE, remain);
 		gdm->tty_dev->send_func(gdm->tty_dev->priv_dev,
 					(void *)(buf + sent_len),
 					sending_len,
-- 
2.41.0


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

* Re: [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant
  2023-08-16  8:53 [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant Jiri Slaby (SUSE)
@ 2023-08-16 11:45 ` Geert Uytterhoeven
  2023-08-16 17:13 ` Nathan Chancellor
  2023-08-17 11:37 ` David Laight
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2023-08-16 11:45 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Nathan Chancellor,
	kernel test robot

On Wed, 16 Aug 2023, Jiri Slaby (SUSE) wrote:
> My thinking was that ulong is the same as size_t everywhere. No, size_t
> is uint on 32bit. So the below commit introduced a build warning on
> 32bit:
> .../gdm724x/gdm_tty.c:165:24: warning: comparison of distinct pointer types ('typeof (2048UL) *' (aka 'unsigned long *') and 'typeof (remain) *' (aka 'unsigned int *'))
>
> To fix this, partially revert the commit (remove constants' suffixes)
> and switch to min_t() in this case instead.
>
> /me would hope for Z (or alike) suffix for constants.
>
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Fixes: c3e5c706aefc (tty: gdm724x: convert counts to size_t)
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202308151953.rNNnAR2N-lkp@intel.com/

Thanks, this fixes the m68k/allmodconfig build.

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

> --- a/drivers/staging/gdm724x/gdm_tty.c
> +++ b/drivers/staging/gdm724x/gdm_tty.c
> @@ -17,9 +17,9 @@
> #define GDM_TTY_MAJOR 0
> #define GDM_TTY_MINOR 32
>
> -#define WRITE_SIZE 2048UL
> +#define WRITE_SIZE 2048
>
> -#define MUX_TX_MAX_SIZE 2048UL
> +#define MUX_TX_MAX_SIZE 2048

You probably want to keep the "U" suffix, so at least both parts
of min() are unsigned.

See also "[PATCH next v3 0/5] minmax: Relax type checks in min() and max().".
https://lore.kernel.org/all/01e3e09005e9434b8f558a893a47c053@AcuMS.aculab.com,

>
> static inline bool gdm_tty_ready(struct gdm *gdm)
> {
> @@ -159,7 +159,7 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
> 		return -ENODEV;
>
> 	while (remain) {
> -		size_t sending_len = min(MUX_TX_MAX_SIZE, remain);
> +		size_t sending_len = min_t(size_t, MUX_TX_MAX_SIZE, remain);
> 		gdm->tty_dev->send_func(gdm->tty_dev->priv_dev,
> 					(void *)(buf + sent_len),
> 					sending_len,
> -- 
> 2.41.0
>
>

Gr{oetje,eeting}s,

 						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
 							    -- Linus Torvalds

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

* Re: [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant
  2023-08-16  8:53 [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant Jiri Slaby (SUSE)
  2023-08-16 11:45 ` Geert Uytterhoeven
@ 2023-08-16 17:13 ` Nathan Chancellor
  2023-08-17 11:37 ` David Laight
  2 siblings, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2023-08-16 17:13 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel, kernel test robot

On Wed, Aug 16, 2023 at 10:53:22AM +0200, Jiri Slaby (SUSE) wrote:
> My thinking was that ulong is the same as size_t everywhere. No, size_t
> is uint on 32bit. So the below commit introduced a build warning on
> 32bit:
> .../gdm724x/gdm_tty.c:165:24: warning: comparison of distinct pointer types ('typeof (2048UL) *' (aka 'unsigned long *') and 'typeof (remain) *' (aka 'unsigned int *'))
> 
> To fix this, partially revert the commit (remove constants' suffixes)
> and switch to min_t() in this case instead.
> 
> /me would hope for Z (or alike) suffix for constants.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Fixes: c3e5c706aefc (tty: gdm724x: convert counts to size_t)
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202308151953.rNNnAR2N-lkp@intel.com/

Tested-by: Nathan Chancellor <nathan@kernel.org> # build

> ---
>  drivers/staging/gdm724x/gdm_tty.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
> index 67d9bf41e836..32b2e817ff04 100644
> --- a/drivers/staging/gdm724x/gdm_tty.c
> +++ b/drivers/staging/gdm724x/gdm_tty.c
> @@ -17,9 +17,9 @@
>  #define GDM_TTY_MAJOR 0
>  #define GDM_TTY_MINOR 32
>  
> -#define WRITE_SIZE 2048UL
> +#define WRITE_SIZE 2048
>  
> -#define MUX_TX_MAX_SIZE 2048UL
> +#define MUX_TX_MAX_SIZE 2048
>  
>  static inline bool gdm_tty_ready(struct gdm *gdm)
>  {
> @@ -159,7 +159,7 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
>  		return -ENODEV;
>  
>  	while (remain) {
> -		size_t sending_len = min(MUX_TX_MAX_SIZE, remain);
> +		size_t sending_len = min_t(size_t, MUX_TX_MAX_SIZE, remain);
>  		gdm->tty_dev->send_func(gdm->tty_dev->priv_dev,
>  					(void *)(buf + sent_len),
>  					sending_len,
> -- 
> 2.41.0
> 

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

* RE: [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant
  2023-08-16  8:53 [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant Jiri Slaby (SUSE)
  2023-08-16 11:45 ` Geert Uytterhoeven
  2023-08-16 17:13 ` Nathan Chancellor
@ 2023-08-17 11:37 ` David Laight
  2 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2023-08-17 11:37 UTC (permalink / raw)
  To: 'Jiri Slaby (SUSE)', gregkh@linuxfoundation.org
  Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nathan Chancellor, kernel test robot

From: Jiri Slaby (SUSE)
> Sent: Wednesday, August 16, 2023 9:53 AM
> 
> My thinking was that ulong is the same as size_t everywhere. No, size_t
> is uint on 32bit. So the below commit introduced a build warning on
> 32bit:
> .../gdm724x/gdm_tty.c:165:24: warning: comparison of distinct pointer types ('typeof (2048UL) *' (aka
> 'unsigned long *') and 'typeof (remain) *' (aka 'unsigned int *'))
> 
> To fix this, partially revert the commit (remove constants' suffixes)
> and switch to min_t() in this case instead.
> 
....
> -		size_t sending_len = min(MUX_TX_MAX_SIZE, remain);
> +		size_t sending_len = min_t(size_t, MUX_TX_MAX_SIZE, remain);

It would be slightly safer to use:
		min(remain, (size_t)MAX_TX_MAX_SIZE);
since that maintains the type check.
(It is also nicer to put the constant second.)

	David

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


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

end of thread, other threads:[~2023-08-17 11:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16  8:53 [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant Jiri Slaby (SUSE)
2023-08-16 11:45 ` Geert Uytterhoeven
2023-08-16 17:13 ` Nathan Chancellor
2023-08-17 11:37 ` David Laight

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).