Re: [PATCH v3 3/3] overflow: Remove is_non_negative() and is_negative()

Vincent Mailhol <[email protected]> Thu, 1 Jan 2026 16:10:36 +0100
Newsgroups org.kernel.vger.linux-sparse,dev.linux.lists.llvm,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-btrfs,org.kernel.vger.linux-hardening,org.kernel.vger.linux-kbuild,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On 20/12/2025 at 12:02, Vincent Mailhol wrote:
> The is_non_negative() and is_negative() function-like macros just
> exist as a workaround to silence the -Wtype-limits warning. Now that
> this warning is disabled, those two macros have lost their raison
> d'ĂȘtre. Remove them.
> 
> This reverts commit dc7fe518b049 ("overflow: Fix -Wtype-limits
> compilation warnings").
> 
> Suggested-by: Nicolas Schier <[email protected]>
> Link: https://lore.kernel.org/all/[email protected]
> Signed-off-by: Vincent Mailhol <[email protected]>

So at the end, this patch got five kernel test robot reports:

  https://lore.kernel.org/all/[email protected]/
  https://lore.kernel.org/all/[email protected]/
  https://lore.kernel.org/all/[email protected]/
  https://lore.kernel.org/all/[email protected]/
  https://lore.kernel.org/all/[email protected]/

All these are the same smatch warning just triggered from a different
place. I think it is still too early to undo that workaround in
include/linux/overflow.h, otherwise developers would be getting that
smatch report too often.

I will send a v4 in which I will drop this patch. This basically means
that the v4 is a revert to v1...

> ---
> Changelog:
> 
>   v1 -> v2: new patch
> ---
>  include/linux/overflow.h | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> index 736f633b2d5f..ab142d60c6b5 100644
> --- a/include/linux/overflow.h
> +++ b/include/linux/overflow.h
> @@ -36,12 +36,6 @@
>  #define __type_min(T) ((T)((T)-type_max(T)-(T)1))
>  #define type_min(t)	__type_min(typeof(t))
>  
> -/*
> - * Avoids triggering -Wtype-limits compilation warning,
> - * while using unsigned data types to check a < 0.
> - */
> -#define is_non_negative(a) ((a) > 0 || (a) == 0)
> -#define is_negative(a) (!(is_non_negative(a)))
>  
>  /*
>   * Allows for effectively applying __must_check to a macro so we can have
> @@ -201,9 +195,9 @@ static inline bool __must_check __must_check_overflow(bool overflow)
>  	typeof(d) _d = d;						\
>  	unsigned long long _a_full = _a;				\
>  	unsigned int _to_shift =					\
> -		is_non_negative(_s) && _s < 8 * sizeof(*d) ? _s : 0;	\
> +		_s >= 0 && _s < 8 * sizeof(*d) ? _s : 0;		\
>  	*_d = (_a_full << _to_shift);					\
> -	(_to_shift != _s || is_negative(*_d) || is_negative(_a) ||	\
> +	(_to_shift != _s || *_d < 0 || _a < 0 ||			\
>  	(*_d >> _to_shift) != _a);					\
>  }))
>  
> 

Yours sincerely,
Vincent Mailhol