Re: [PATCH next v4 1/5] minmax: Add umin(a, b) and umax(a, b)

From: Dan Carpenter
Date: Fri Jan 12 2024 - 07:50:17 EST


On Mon, Sep 18, 2023 at 08:16:30AM +0000, David Laight wrote:
> +/**
> + * umin - return minimum of two non-negative values
> + * Signed types are zero extended to match a larger unsigned type.
> + * @x: first value
> + * @y: second value
> + */
> +#define umin(x, y) \
> + __careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, <)

Why do we match "a larger unsigned type" instead of ULL_MAX? Presumably
it helps performance somehow... I agree that it's probably fine but I
would be more comfortable if it skipped UINT_MAX and jumped directly to
ULONG_MAX. These days 4 gigs is small potatoes. The vmalloc() function
can allocate 4G so we've had integer overflow bugs with this before.

regards,
dan carpenter