Skip to contentSkip to conversation

uapi: Use UAPI definitions of INT_MAX and INT_MIN

PATCH Applied Thomas Weißschuh 2 participants 5 messages Jan 13 – Jan 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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]>
#1 lore raw

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
new file mode 100644
index 000000000000..8166c639b518
@@ -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
#2 lore raw

PATCH v2 2/3 ethtool: uapi: Use UAPI definition of INT_MAX

In reply to Thomas Weißschuh

Using <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
index eb7ff2602fbb..70a0ef08f6f5 100644
@@ -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
#3 lore raw

PATCH v2 3/3 netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN

In reply to Thomas Weißschuh

Using <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
index 1610fdbab98d..f6e8d1e05c97 100644
@@ -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		6
 
 enum 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
index 155e77d6a42d..439d3c59862b 100644
@@ -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
index 80aa9b0799af..0e40d00b37fa 100644
@@ -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
#4 lore raw
In reply to Thomas Weißschuh
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 to INT_MAX and INT_MIN introduces a dependency on a libc, which UAPI headers should not do.

Introduce and use equivalent UAPI constants.

[...]

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