Re: [PATCH] usb: Replace a < b ? a : b construct with min_t(type, a, b) in drivers/usb

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 18, 2019 at 08:00:28AM -0700, dmg wrote:
> 
> Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> writes:
> 
> > On Mon, Jun 17, 2019 at 04:30:50PM -0700, dmg@xxxxxxxxxxxxxxxxx wrote:
> >> From: Daniel M German <dmg@xxxxxxxxxxxxxxxxx>
> >>
> >> Use min_t to find the minimum of two values instead of using the ?: operator.
> >
> > Why is min_t() needed for all of these and not just min()?
> 
> The use of min triggers a compilation warning (see below), which min_t is supposed to
> address (from min_t comment: 'min()/max() macros that also do strict type-checking.. See the
> "unnecessary" pointer comparison.", from include/linux/kernel')
> 
>    In file included from drivers/usb/misc/adutux.c:19:
>    drivers/usb/misc/adutux.c: In function ‘adu_read’:
>    ./include/linux/kernel.h:818:29: warning: comparison of distinct pointer types lacks a cast
>       (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
>                                 ^~
>    ./include/linux/kernel.h:832:4: note: in expansion of macro ‘__typecheck’
>       (__typecheck(x, y) && __no_side_effects(x, y))
>        ^~~~~~~~~~~
>    ./include/linux/kernel.h:842:24: note: in expansion of macro ‘__safe_cmp’
>      __builtin_choose_expr(__safe_cmp(x, y), \
>                            ^~~~~~~~~~
>    ./include/linux/kernel.h:851:19: note: in expansion of macro ‘__careful_cmp’
>     #define min(x, y) __careful_cmp(x, y, <)
>                       ^~~~~~~~~~~~~
>    drivers/usb/misc/adutux.c:382:34: note: in expansion of macro ‘min’
>                         int amount = min(bytes_to_read, data_in_secondary);
>                                      ^~~

Yes, but is it needed for all of these?

And what about just changing the types of those variables to be the
same?  Does the cast have to be there?

thanks,

greg k-h



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux