move more limits from kernel.h to limits.h and standardize their definitions
authorRasmus Villemoes <ravi@prevas.dk>
Mon, 7 Jul 2025 20:36:53 +0000 (22:36 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 14 Jul 2025 18:43:28 +0000 (12:43 -0600)
commitdc323f3bee318514af9d7c6fed1e01c712bc71ae
tree2f552b86cd2e9a650ea33ebed0ce32cecbbdd78f
parente37de002fac3895e8d0b60ae2015e17bb33e2b5b
move more limits from kernel.h to limits.h and standardize their definitions

In a customer project that was building a stand-alone application, I
hit a problem related to the fact that our LONG_MAX and friends are
not standards-compliant, in that they are not "suitable for use in #if
preprocessing directives"

... /toolchain_none/arm-cortexa8-eabi/sys-include/machine/_default_types.h:25:31: error: missing binary operator before token "long"
   25 |   || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
      |                               ^~~~~~~~~

So following up on commit 13de8483388 ("mbedtls: add mbedtls into the
build system"), move the rest of the macros associated to the standard
C types {signed,unsigned} {char, short, int, long, long long} (and of
course bare 'char') to limits.h.

Make use of the fact that both gcc and clang provide suitable
predefined __FOO_MAX__ macros for the signed types, and use a standard
scheme for defining the FOO_MIN and UFOO_MAX macros in terms of
FOO_MAX.

Note that suffixes like L and ULL are allowed for preprocessor
integers; it is (casts) which are not. And using appropriate suffixes,
we can arrange for the type of e.g. UINT_MAX to be "unsigned int" due
to integer promotion rules.

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
include/limits.h
include/linux/kernel.h