lkml.org 
[lkml]   [2023]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH] tty: gdm724x: use min_t() for size_t varable and a constant
Date
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)

\
 
 \ /
  Last update: 2023-08-17 13:38    [W:0.043 / U:2.632 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site