public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] uapi: Use UAPI definitions of INT_MAX and INT_MIN
@ 2026-01-13  7:44 Thomas Weißschuh
  2026-01-13  7:44 ` [PATCH v2 1/3] uapi: add INT_MAX and INT_MIN constants Thomas Weißschuh
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-01-13  7:44 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Andrew Lunn, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, Phil Sutter
  Cc: Arnd Bergmann, linux-kernel, netdev, netfilter-devel, coreteam,
	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.

Introduce and use equivalent UAPI constants.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Changes in v2:
- Use uapi/linux/typelimits.h over uapi/linux/limits.h
- Drop RFC status
- Link to v1: https://lore.kernel.org/r/20260105-uapi-limits-v1-0-023bc7a13037@linutronix.de

---
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,
-- 
Thomas Weißschuh <thomas.weissschuh@linutronix.de>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] uapi: add INT_MAX and INT_MIN constants
  2026-01-13  7:44 [PATCH v2 0/3] uapi: Use UAPI definitions of INT_MAX and INT_MIN Thomas Weißschuh
@ 2026-01-13  7:44 ` Thomas Weißschuh
  2026-01-13  7:44 ` [PATCH v2 2/3] ethtool: uapi: Use UAPI definition of INT_MAX Thomas Weißschuh
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-01-13  7:44 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Andrew Lunn, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, Phil Sutter
  Cc: Arnd Bergmann, linux-kernel, netdev, netfilter-devel, coreteam,
	Thomas Weißschuh

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.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 include/uapi/linux/typelimits.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/uapi/linux/typelimits.h b/include/uapi/linux/typelimits.h
new file mode 100644
index 000000000000..8166c639b518
--- /dev/null
+++ b/include/uapi/linux/typelimits.h
@@ -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 */

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] ethtool: uapi: Use UAPI definition of INT_MAX
  2026-01-13  7:44 [PATCH v2 0/3] uapi: Use UAPI definitions of INT_MAX and INT_MIN Thomas Weißschuh
  2026-01-13  7:44 ` [PATCH v2 1/3] uapi: add INT_MAX and INT_MIN constants Thomas Weißschuh
@ 2026-01-13  7:44 ` Thomas Weißschuh
  2026-01-13  7:44 ` [PATCH v2 3/3] netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN Thomas Weißschuh
  2026-01-19 14:19 ` [PATCH v2 0/3] uapi: Use UAPI definitions " patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-01-13  7:44 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Andrew Lunn, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, Phil Sutter
  Cc: Arnd Bergmann, linux-kernel, netdev, netfilter-devel, coreteam,
	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.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 include/uapi/linux/ethtool.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index eb7ff2602fbb..70a0ef08f6f5 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -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. */

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN
  2026-01-13  7:44 [PATCH v2 0/3] uapi: Use UAPI definitions of INT_MAX and INT_MIN Thomas Weißschuh
  2026-01-13  7:44 ` [PATCH v2 1/3] uapi: add INT_MAX and INT_MIN constants Thomas Weißschuh
  2026-01-13  7:44 ` [PATCH v2 2/3] ethtool: uapi: Use UAPI definition of INT_MAX Thomas Weißschuh
@ 2026-01-13  7:44 ` Thomas Weißschuh
  2026-01-19 14:19 ` [PATCH v2 0/3] uapi: Use UAPI definitions " patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-01-13  7:44 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Andrew Lunn, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, Phil Sutter
  Cc: Arnd Bergmann, linux-kernel, netdev, netfilter-devel, coreteam,
	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.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 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(-)

diff --git a/include/uapi/linux/netfilter_bridge.h b/include/uapi/linux/netfilter_bridge.h
index 1610fdbab98d..f6e8d1e05c97 100644
--- a/include/uapi/linux/netfilter_bridge.h
+++ b/include/uapi/linux/netfilter_bridge.h
@@ -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 */
diff --git a/include/uapi/linux/netfilter_ipv4.h b/include/uapi/linux/netfilter_ipv4.h
index 155e77d6a42d..439d3c59862b 100644
--- a/include/uapi/linux/netfilter_ipv4.h
+++ b/include/uapi/linux/netfilter_ipv4.h
@@ -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: */
diff --git a/include/uapi/linux/netfilter_ipv6.h b/include/uapi/linux/netfilter_ipv6.h
index 80aa9b0799af..0e40d00b37fa 100644
--- a/include/uapi/linux/netfilter_ipv6.h
+++ b/include/uapi/linux/netfilter_ipv6.h
@@ -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,
 };
 
 

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/3] uapi: Use UAPI definitions of INT_MAX and INT_MIN
  2026-01-13  7:44 [PATCH v2 0/3] uapi: Use UAPI definitions of INT_MAX and INT_MIN Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2026-01-13  7:44 ` [PATCH v2 3/3] netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN Thomas Weißschuh
@ 2026-01-19 14:19 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-19 14:19 UTC (permalink / raw)
  To: =?utf-8?q?Thomas_Wei=C3=9Fschuh_=3Cthomas=2Eweissschuh=40linutronix=2Ede=3E?=
  Cc: davem, edumazet, kuba, pabeni, horms, andrew, pablo, kadlec, fw,
	phil, arnd, linux-kernel, netdev, netfilter-devel, coreteam

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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.
> 
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-01-19 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-13  7:44 [PATCH v2 0/3] uapi: Use UAPI definitions of INT_MAX and INT_MIN Thomas Weißschuh
2026-01-13  7:44 ` [PATCH v2 1/3] uapi: add INT_MAX and INT_MIN constants Thomas Weißschuh
2026-01-13  7:44 ` [PATCH v2 2/3] ethtool: uapi: Use UAPI definition of INT_MAX Thomas Weißschuh
2026-01-13  7:44 ` [PATCH v2 3/3] netfilter: uapi: Use UAPI definition of INT_MAX and INT_MIN Thomas Weißschuh
2026-01-19 14:19 ` [PATCH v2 0/3] uapi: Use UAPI definitions " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox