Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

uapi: move constants from <linux/kernel.h> to <linux/const.h>

and include <linux/const.h> in UAPI headers instead of <linux/kernel.h>.

The reason is to avoid indirect <linux/sysinfo.h> include when using
some network headers: <linux/netlink.h> or others -> <linux/kernel.h>
-> <linux/sysinfo.h>.

This indirect include causes on MUSL redefinition of struct sysinfo when
included both <sys/sysinfo.h> and some of UAPI headers:

In file included from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/kernel.h:5,
from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/netlink.h:5,
from ../include/tst_netlink.h:14,
from tst_crypto.c:13:
x86_64-buildroot-linux-musl/sysroot/usr/include/linux/sysinfo.h:8:8: error: redefinition of `struct sysinfo'
struct sysinfo {
^~~~~~~
In file included from ../include/tst_safe_macros.h:15,
from ../include/tst_test.h:93,
from tst_crypto.c:11:
x86_64-buildroot-linux-musl/sysroot/usr/include/sys/sysinfo.h:10:8: note: originally defined here

Link: https://lkml.kernel.org/r/20201015190013.8901-1-petr.vorel@gmail.com
Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
Suggested-by: Rich Felker <dalias@aerifal.cx>
Acked-by: Rich Felker <dalias@libc.org>
Cc: Peter Korsgaard <peter@korsgaard.com>
Cc: Baruch Siach <baruch@tkos.co.il>
Cc: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Petr Vorel and committed by
Linus Torvalds
a85cbe61 ebb2bdce

+12 -14
+5
include/uapi/linux/const.h
··· 28 28 #define _BITUL(x) (_UL(1) << (x)) 29 29 #define _BITULL(x) (_ULL(1) << (x)) 30 30 31 + #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) 32 + #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) 33 + 34 + #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 35 + 31 36 #endif /* _UAPI_LINUX_CONST_H */
+1 -1
include/uapi/linux/ethtool.h
··· 14 14 #ifndef _UAPI_LINUX_ETHTOOL_H 15 15 #define _UAPI_LINUX_ETHTOOL_H 16 16 17 - #include <linux/kernel.h> 17 + #include <linux/const.h> 18 18 #include <linux/types.h> 19 19 #include <linux/if_ether.h> 20 20
+1 -8
include/uapi/linux/kernel.h
··· 3 3 #define _UAPI_LINUX_KERNEL_H 4 4 5 5 #include <linux/sysinfo.h> 6 - 7 - /* 8 - * 'kernel.h' contains some often-used function prototypes etc 9 - */ 10 - #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) 11 - #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) 12 - 13 - #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 6 + #include <linux/const.h> 14 7 15 8 #endif /* _UAPI_LINUX_KERNEL_H */
+1 -1
include/uapi/linux/lightnvm.h
··· 21 21 #define _UAPI_LINUX_LIGHTNVM_H 22 22 23 23 #ifdef __KERNEL__ 24 - #include <linux/kernel.h> 24 + #include <linux/const.h> 25 25 #include <linux/ioctl.h> 26 26 #else /* __KERNEL__ */ 27 27 #include <stdio.h>
+1 -1
include/uapi/linux/mroute6.h
··· 2 2 #ifndef _UAPI__LINUX_MROUTE6_H 3 3 #define _UAPI__LINUX_MROUTE6_H 4 4 5 - #include <linux/kernel.h> 5 + #include <linux/const.h> 6 6 #include <linux/types.h> 7 7 #include <linux/sockios.h> 8 8 #include <linux/in6.h> /* For struct sockaddr_in6. */
+1 -1
include/uapi/linux/netfilter/x_tables.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 2 #ifndef _UAPI_X_TABLES_H 3 3 #define _UAPI_X_TABLES_H 4 - #include <linux/kernel.h> 4 + #include <linux/const.h> 5 5 #include <linux/types.h> 6 6 7 7 #define XT_FUNCTION_MAXNAMELEN 30
+1 -1
include/uapi/linux/netlink.h
··· 2 2 #ifndef _UAPI__LINUX_NETLINK_H 3 3 #define _UAPI__LINUX_NETLINK_H 4 4 5 - #include <linux/kernel.h> 5 + #include <linux/const.h> 6 6 #include <linux/socket.h> /* for __kernel_sa_family_t */ 7 7 #include <linux/types.h> 8 8
+1 -1
include/uapi/linux/sysctl.h
··· 23 23 #ifndef _UAPI_LINUX_SYSCTL_H 24 24 #define _UAPI_LINUX_SYSCTL_H 25 25 26 - #include <linux/kernel.h> 26 + #include <linux/const.h> 27 27 #include <linux/types.h> 28 28 #include <linux/compiler.h> 29 29