RE: [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant

From: David Laight
Date: Thu Aug 17 2023 - 07:38:18 EST


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)