git: b99954433d42 - main - linux: Fix some problems with header pollution

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 15 May 2026 01:10:27 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=b99954433d42d978b257e846dbfe568e9af7b140

commit b99954433d42d978b257e846dbfe568e9af7b140
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-05-15 00:39:25 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-05-15 00:39:25 +0000

    linux: Fix some problems with header pollution
    
    - Avoid including sys/proc.h in linux_vdso_gtod.c.  It's not needed, but
      the implicit inclusion of sys/param.h via sys/ucred.h->bsm/audit.h was
      bringing in some required definitions.
    - Include a couple of required headers: sys/time.h (for struct bintime),
      and limits.h (for INT_MAX).
    - Move some helpers from linux.h, which depend on sys/param.h for NODEV,
      to the one CU where they're actually used.
    
    No functional change intended.
    
    Reviewed by:    imp, kib, emaste
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D56982
---
 sys/amd64/linux/linux_vdso_gtod.c     |  4 ++-
 sys/amd64/linux32/linux32_vdso_gtod.c |  4 ++-
 sys/arm64/linux/linux_vdso_gtod.c     |  4 ++-
 sys/compat/linux/linux.h              | 50 -----------------------------------
 sys/compat/linux/linux_stats.c        | 46 ++++++++++++++++++++++++++++++++
 sys/i386/linux/linux_vdso_gtod.c      |  4 ++-
 6 files changed, 58 insertions(+), 54 deletions(-)

diff --git a/sys/amd64/linux/linux_vdso_gtod.c b/sys/amd64/linux/linux_vdso_gtod.c
index abe42d51a3ac..12c5c96dcead 100644
--- a/sys/amd64/linux/linux_vdso_gtod.c
+++ b/sys/amd64/linux/linux_vdso_gtod.c
@@ -27,12 +27,14 @@
 
 #include <sys/elf.h>
 #include <sys/errno.h>
-#include <sys/proc.h>
 #include <sys/stdarg.h>
 #include <sys/stddef.h>
+#include <sys/time.h>
 #define	_KERNEL
 #include <sys/vdso.h>
 #undef	_KERNEL
+
+#include <limits.h>
 #include <stdbool.h>
 
 #include <machine/atomic.h>
diff --git a/sys/amd64/linux32/linux32_vdso_gtod.c b/sys/amd64/linux32/linux32_vdso_gtod.c
index f32db30057d0..ff4b372ea3bc 100644
--- a/sys/amd64/linux32/linux32_vdso_gtod.c
+++ b/sys/amd64/linux32/linux32_vdso_gtod.c
@@ -27,12 +27,14 @@
 
 #include <sys/elf.h>
 #include <sys/errno.h>
-#include <sys/proc.h>
 #include <sys/stdarg.h>
 #include <sys/stddef.h>
+#include <sys/time.h>
 #define	_KERNEL
 #include <sys/vdso.h>
 #undef	_KERNEL
+
+#include <limits.h>
 #include <stdbool.h>
 
 #include <i386/include/atomic.h>
diff --git a/sys/arm64/linux/linux_vdso_gtod.c b/sys/arm64/linux/linux_vdso_gtod.c
index 203c76b6e3a9..55f039b74593 100644
--- a/sys/arm64/linux/linux_vdso_gtod.c
+++ b/sys/arm64/linux/linux_vdso_gtod.c
@@ -28,12 +28,14 @@
 
 #include <sys/elf.h>
 #include <sys/errno.h>
-#include <sys/proc.h>
 #include <sys/stdarg.h>
 #include <sys/stddef.h>
+#include <sys/time.h>
 #define	_KERNEL
 #include <sys/vdso.h>
 #undef	_KERNEL
+
+#include <limits.h>
 #include <stdbool.h>
 
 #include <machine/atomic.h>
diff --git a/sys/compat/linux/linux.h b/sys/compat/linux/linux.h
index 67acd726a503..a9f753cd55b7 100644
--- a/sys/compat/linux/linux.h
+++ b/sys/compat/linux/linux.h
@@ -28,58 +28,8 @@
 #ifndef _LINUX_MI_H_
 #define _LINUX_MI_H_
 
-/*
- * Machine independent set of types for the Linux types.
- */
 typedef uint32_t	l_dev_t;
 
-/*
- * Linux dev_t conversion routines.
- *
- * As of version 2.6.0 of the Linux kernel, dev_t is a 32-bit quantity
- * with 12 bits set asaid for the major number and 20 for the minor number.
- * The in-kernel dev_t encoded as MMMmmmmm, where M is a hex digit of the
- * major number and m is a hex digit of the minor number.
- * The user-space dev_t encoded as mmmM MMmm, where M and m is the major
- * and minor numbers accordingly. This is downward compatible with legacy
- * systems where dev_t is 16 bits wide, encoded as MMmm.
- * In glibc dev_t is a 64-bit quantity, with 32-bit major and minor numbers,
- * encoded as MMMM Mmmm mmmM MMmm. This is downward compatible with the Linux
- * kernel and with legacy systems where dev_t is 16 bits wide.
- *
- * In the FreeBSD dev_t is a 64-bit quantity. The major and minor numbers
- * are encoded as MMMmmmMm, therefore conversion of the device numbers between
- * Linux user-space and FreeBSD kernel required.
- */
-static __inline l_dev_t
-linux_encode_dev(int _major, int _minor)
-{
-
-	return ((_minor & 0xff) | ((_major & 0xfff) << 8) |
-	    (((_minor & ~0xff) << 12) & 0xfff00000));
-}
-
-static __inline l_dev_t
-linux_new_encode_dev(dev_t _dev)
-{
-
-	return (_dev == NODEV ? 0 : linux_encode_dev(major(_dev), minor(_dev)));
-}
-
-static __inline int
-linux_encode_major(dev_t _dev)
-{
-
-	return (_dev == NODEV ? 0 : major(_dev) & 0xfff);
-}
-
-static __inline int
-linux_encode_minor(dev_t _dev)
-{
-
-	return (_dev == NODEV ? 0 : minor(_dev) & 0xfffff);
-}
-
 static __inline int
 linux_decode_major(l_dev_t _dev)
 {
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index 6f96a219003b..5ac9394f3601 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -58,6 +58,52 @@
 #include <compat/linux/linux_file.h>
 #include <compat/linux/linux_util.h>
 
+/*
+ * Linux dev_t conversion routines.
+ *
+ * As of version 2.6.0 of the Linux kernel, dev_t is a 32-bit quantity
+ * with 12 bits set asaid for the major number and 20 for the minor number.
+ * The in-kernel dev_t encoded as MMMmmmmm, where M is a hex digit of the
+ * major number and m is a hex digit of the minor number.
+ * The user-space dev_t encoded as mmmM MMmm, where M and m is the major
+ * and minor numbers accordingly. This is downward compatible with legacy
+ * systems where dev_t is 16 bits wide, encoded as MMmm.
+ * In glibc dev_t is a 64-bit quantity, with 32-bit major and minor numbers,
+ * encoded as MMMM Mmmm mmmM MMmm. This is downward compatible with the Linux
+ * kernel and with legacy systems where dev_t is 16 bits wide.
+ *
+ * In the FreeBSD dev_t is a 64-bit quantity. The major and minor numbers
+ * are encoded as MMMmmmMm, therefore conversion of the device numbers between
+ * Linux user-space and FreeBSD kernel required.
+ */
+static l_dev_t
+linux_encode_dev(int _major, int _minor)
+{
+
+	return ((_minor & 0xff) | ((_major & 0xfff) << 8) |
+	    (((_minor & ~0xff) << 12) & 0xfff00000));
+}
+
+static l_dev_t
+linux_new_encode_dev(dev_t _dev)
+{
+
+	return (_dev == NODEV ? 0 : linux_encode_dev(major(_dev), minor(_dev)));
+}
+
+static int
+linux_encode_major(dev_t _dev)
+{
+
+	return (_dev == NODEV ? 0 : major(_dev) & 0xfff);
+}
+
+static int
+linux_encode_minor(dev_t _dev)
+{
+
+	return (_dev == NODEV ? 0 : minor(_dev) & 0xfffff);
+}
 
 static int
 linux_kern_fstat(struct thread *td, int fd, struct stat *sbp)
diff --git a/sys/i386/linux/linux_vdso_gtod.c b/sys/i386/linux/linux_vdso_gtod.c
index 00367d82139e..336f8d4c290d 100644
--- a/sys/i386/linux/linux_vdso_gtod.c
+++ b/sys/i386/linux/linux_vdso_gtod.c
@@ -27,12 +27,14 @@
 
 #include <sys/elf.h>
 #include <sys/errno.h>
-#include <sys/proc.h>
 #include <sys/stdarg.h>
 #include <sys/stddef.h>
+#include <sys/time.h>
 #define	_KERNEL
 #include <sys/vdso.h>
 #undef	_KERNEL
+
+#include <limits.h>
 #include <stdbool.h>
 
 #include <machine/atomic.h>