uapi: Use UAPI definitions of INT_MAX and INT_MIN
Subsystems (4)
v2 cover uapi: Use UAPI definitions of INT_MAX and INT_MIN
Using <limits.h> to gain access to INT_MAX and INT_MIN introduces a dependency on a libc, which UAPI headers should not do.
Introduce and use equivalent UAPI constants.
---
Changes in v2:
- Use uapi/linux/typelimits.h over uapi/linux/limits.h
- Drop RFC status
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Thomas Weißschuh (3):
uapi: add INT_MAX and INT_MIN constants
ethtool: uapi: Use UAPI definition of INT_MAX
netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN
include/uapi/linux/ethtool.h | 7 ++----- include/uapi/linux/netfilter_bridge.h | 9 +++------ include/uapi/linux/netfilter_ipv4.h | 9 ++++----- include/uapi/linux/netfilter_ipv6.h | 7 +++---- include/uapi/linux/typelimits.h | 8 ++++++++ 5 files changed, 20 insertions(+), 20 deletions(-)
---
base-commit: 16ce6e6fa946ca6fd1e4fce6926b52b6263d98a8
change-id: 20251229-uapi-limits-56c45c9369c9
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
PATCH v2 1/3 uapi: add INT_MAX and INT_MIN constants
Some UAPI headers use INT_MAX and INT_MIN. Currently they include <limits.h> for their definitions, which introduces a problematic dependency on libc.
Add custom, namespaced definitions of INT_MAX and INT_MIN using the same values as the regular kernel code.
These definitions are not added to uapi/linux/limits.h, as that header will conflict with libc definitions on some platforms.
--- include/uapi/linux/typelimits.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/uapi/linux/typelimits.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_TYPELIMITS_H +#define _UAPI_LINUX_TYPELIMITS_H + +#define __KERNEL_INT_MAX ((int)(~0U >> 1)) +#define __KERNEL_INT_MIN (-__KERNEL_INT_MAX - 1) + +#endif /* _UAPI_LINUX_TYPELIMITS_H */
Signature · 1 line
2.52.0
PATCH v2 2/3 ethtool: uapi: Use UAPI definition of INT_MAX
In reply to Thomas WeißschuhUsing <limits.h> to gain access to INT_MAX introduces a dependency on a libc, which UAPI headers should not do.
Use the equivalent UAPI constant.
--- include/uapi/linux/ethtool.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
include/uapi/linux/ethtool.h +2 -5
@@ -15,13 +15,10 @@#define _UAPI_LINUX_ETHTOOL_H#include <linux/const.h> +#include <linux/typelimits.h> #include <linux/types.h> #include <linux/if_ether.h> -#ifndef __KERNEL__ -#include <limits.h> /* for INT_MAX */ -#endif -/* All structures exposed to userland should be defined such that they * have the same layout for 32-bit and 64-bit userland. */
@@ -2200,7 +2197,7 @@ enum ethtool_link_mode_bit_indices {static inline int ethtool_validate_speed (__u32 speed) { -return speed <=INT_MAX || speed == (__u32 )SPEED_UNKNOWN ; +return speed <= __KERNEL_INT_MAX || speed == (__u32 )SPEED_UNKNOWN ; }/* Duplex, half or full. */
Signature · 1 line
2.52.0
PATCH v2 3/3 netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN
In reply to Thomas WeißschuhUsing <limits.h> to gain access to INT_MAX and INT_MIN introduces a dependency on a libc, which UAPI headers should not do.
Use the equivalent UAPI constants.
--- include/uapi/linux/netfilter_bridge.h | 9 +++------ include/uapi/linux/netfilter_ipv4.h | 9 ++++----- include/uapi/linux/netfilter_ipv6.h | 7 +++---- 3 files changed, 10 insertions(+), 15 deletions(-)
include/uapi/linux/netfilter_bridge.h +3 -6
@@ -10,10 +10,7 @@#include <linux/if_ether.h> #include <linux/if_vlan.h> #include <linux/if_pppox.h> - -#ifndef __KERNEL__ -#include <limits.h> /* for INT_MIN, INT_MAX */ -#endif +#include <linux/typelimits.h> /* Bridge Hooks */ /* After promisc drops, checksum checks. */
@@ -31,14 +28,14 @@#define NF_BR_NUMHOOKS 6enum nf_br_hook_priorities { -NF_BR_PRI_FIRST =INT_MIN , +NF_BR_PRI_FIRST = __KERNEL_INT_MIN,NF_BR_PRI_NAT_DST_BRIDGED =-300 ,NF_BR_PRI_FILTER_BRIDGED =-200 ,NF_BR_PRI_BRNF =0 ,NF_BR_PRI_NAT_DST_OTHER =100 ,NF_BR_PRI_FILTER_OTHER =200 ,NF_BR_PRI_NAT_SRC =300 , -NF_BR_PRI_LAST =INT_MAX , +NF_BR_PRI_LAST = __KERNEL_INT_MAX, };#endif /* _UAPI__LINUX_BRIDGE_NETFILTER_H */
include/uapi/linux/netfilter_ipv4.h +4 -5
@@ -7,12 +7,11 @@#include <linux/netfilter.h> +#include <linux/typelimits.h> /* only for userspace compatibility */ #ifndef __KERNEL__ -#include <limits.h> /* for INT_MIN, INT_MAX */ -/* IP Hooks */ /* After promisc drops, checksum checks. */ #define NF_IP_PRE_ROUTING 0
@@ -28,7 +27,7 @@#endif /* ! __KERNEL__ */ enum nf_ip_hook_priorities { -NF_IP_PRI_FIRST =INT_MIN , +NF_IP_PRI_FIRST = __KERNEL_INT_MIN,NF_IP_PRI_RAW_BEFORE_DEFRAG =-450 ,NF_IP_PRI_CONNTRACK_DEFRAG =-400 ,NF_IP_PRI_RAW =-300 ,
@@ -41,8 +40,8 @@ enum nf_ip_hook_priorities {NF_IP_PRI_NAT_SRC =100 ,NF_IP_PRI_SELINUX_LAST =225 ,NF_IP_PRI_CONNTRACK_HELPER =300 , -NF_IP_PRI_CONNTRACK_CONFIRM =INT_MAX , - NF_IP_PRI_LAST = INT_MAX, +NF_IP_PRI_CONNTRACK_CONFIRM = __KERNEL_INT_MAX, + NF_IP_PRI_LAST = __KERNEL_INT_MAX, };/* Arguments for setsockopt SOL_IP: */
include/uapi/linux/netfilter_ipv6.h +3 -4
@@ -10,12 +10,11 @@#include <linux/netfilter.h> +#include <linux/typelimits.h> /* only for userspace compatibility */ #ifndef __KERNEL__ -#include <limits.h> /* for INT_MIN, INT_MAX */ -/* IP6 Hooks */ /* After promisc drops, checksum checks. */ #define NF_IP6_PRE_ROUTING 0
@@ -32,7 +31,7 @@enum nf_ip6_hook_priorities { -NF_IP6_PRI_FIRST =INT_MIN , +NF_IP6_PRI_FIRST = __KERNEL_INT_MIN,NF_IP6_PRI_RAW_BEFORE_DEFRAG =-450 ,NF_IP6_PRI_CONNTRACK_DEFRAG =-400 ,NF_IP6_PRI_RAW =-300 ,
@@ -45,7 +44,7 @@ enum nf_ip6_hook_priorities {NF_IP6_PRI_NAT_SRC =100 ,NF_IP6_PRI_SELINUX_LAST =225 ,NF_IP6_PRI_CONNTRACK_HELPER =300 , - NF_IP6_PRI_LAST = INT_MAX, + NF_IP6_PRI_LAST = __KERNEL_INT_MAX, };
Signature · 1 line
2.52.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Tue, 13 Jan 2026 08:44:16 +0100 you wrote:
Using <
limits.h> to gain access toINT_MAXandINT_MINintroduces a dependency on a libc, which UAPI headers should not do.Introduce and use equivalent UAPI constants.
Signed-off-by Thomas Weißschuh <[email protected]>[...]
Here is the summary with links:
- [v2,1/3] uapi: add INT_MAX and INT_MIN constants
https://git.kernel.org/netdev/net-next/c/ca9d74eb5f6a - [v2,2/3] ethtool: uapi: Use UAPI definition of INT_MAX https://git.kernel.org/netdev/net-next/c/a8a11e5237ae - [v2,3/3] netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN https://git.kernel.org/netdev/net-next/c/0b3877bec78b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html