From: [email protected]
> Sent: 18 June 2019 00:31
> Use min_t to find the minimum of two values instead of using the ?: operator.
>
> This change does not alter functionality. It is merely cosmetic intended to
> improve the readability of the code.
>
> Signed-off-by: Daniel M German <[email protected]>
> ---
> drivers/usb/gadget/function/u_ether.c | 2 +-
> drivers/usb/misc/adutux.c | 2 +-
> drivers/usb/storage/realtek_cr.c | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/u_ether.c
> b/drivers/usb/gadget/function/u_ether.c
> index 737bd77a575d..f6ba46684ddb 100644
> --- a/drivers/usb/gadget/function/u_ether.c
> +++ b/drivers/usb/gadget/function/u_ether.c
> @@ -1006,7 +1006,7 @@ int gether_get_ifname(struct net_device *net, char
> *name, int len)
> rtnl_lock();
> ret = snprintf(name, len, "%s\n", netdev_name(net));
> rtnl_unlock();
> - return ret < len ? ret : len;
> + return min_t(int, ret, len);
> }
I'm not sure using min() or min_t() helps readability here.
In any case that code fragment looks broken!
Were buf[] too small the length returned would include a '\0'.
Now it is quite likely that the overflow is actually impossible
(provided buf[] has room for the '\n').
OTOH the 'correct' fix is to replace the snprintf() with scnprintf()
and remove the 'min()' completely.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT,
UK
Registration No: 1397386 (Wales)