agpgart.h: do not include <stdlib.h> from exported header
Subsystems (2)
PATCH 1/2 agpgart.h: do not include <stdlib.h> from exported header
Commit 35d0f1d54ecd ("include/uapi/linux/agpgart.h: include stdlib.h in userspace") included <stdlib.h> to fix the unknown size_t error, but I do not think it is the right fix.
This header already uses __kernel_size_t a few lines below.
Replace the remaining size_t, and stop including <stdlib.h>.
---
include/uapi/linux/agpgart.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
include/uapi/linux/agpgart.h +4 -5
@@ -52,7 +52,6 @@ #ifndef __KERNEL__ #include <linux/types.h> -#include <stdlib.h> struct agp_version { __u16 major;
@@ -64,10 +63,10 @@ typedef struct _agp_info {__u32 bridge_id;/* bridge vendor/device */ __u32 agp_mode;/* mode info of bridge */ unsigned long aper_base;/* base of aperture */ -size_t aper_size;/* size of aperture */ -size_t pg_total;/* max pages (swap + system) */ -size_t pg_system;/* max pages (system) */ -size_t pg_used;/* current pages used */ +__kernel_size_t aper_size;/* size of aperture */ +__kernel_size_t pg_total;/* max pages (swap + system) */ +__kernel_size_t pg_system;/* max pages (system) */ +__kernel_size_t pg_used;/* current pages used */ } agp_info; typedef struct _agp_setup {
Signature · 1 line
2.32.0
PATCH 2/2 kbuild: forbid exported headers from including <stdint.h>, <stdbool.h>
Some UAPI headers included <stdlib.h>, like this:
#ifndef __KERNEL__ #include <stdlib.h> #endif
As it turned out, they just included it for no good reason.
After some fixes, now I can compile-test UAPI headers (CONFIG_UAPI_HEADER_TEST=y) without <stdlib.h> included.
To avoid somebody getting it back again, this commit adds the dummy header, usr/dummy-include/stdlib.h
I added $(srctree)/usr/dummy-include to the header search paths. Because it is searched before the system directories, if someone tries to include <stdlib.h>, they will see the error message.
While I am here, I also replaced $(objtree)/usr/include with $(obj), but it is just a small refactoring.
If we achieve the situation where none of system headers is included from exported kernel headers (i.e. kernel headers become self-contained), we might be able to add -nostdinc, but that is much far from where we stand now. (see many no-header-test lines in usr/include/Makefile)
As a realistic solution, you can forbid header inclusion individually by putting a dummy header into usr/dummy-include/.
Currently, no header include <stdbool.h>. I put it as well before somebody attempts to use it.
---
usr/dummy-include/stdbool.h | 7 +++++++ usr/dummy-include/stdlib.h | 7 +++++++ usr/include/Makefile | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 usr/dummy-include/stdbool.h create mode 100644 usr/dummy-include/stdlib.h
usr/dummy-include/stdbool.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _STDBOOL_H +#define _STDBOOL_H + +#error "Please do not include <stdbool.h> from exported headers" + +#endif /* _STDBOOL_H */
usr/dummy-include/stdlib.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _STDLIB_H +#define _STDLIB_H + +#error "Please do not include <stdlib.h> from exported headers" + +#endif /* _STDLIB_H */
usr/include/Makefile +1 -1
@@ -15,7 +15,7 @@ UAPI_CFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) # USERCFLAGS might contain sysroot location for CC. UAPI_CFLAGS += $(USERCFLAGS) -override c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I$(objtree)/usr/include +override c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I $(obj) -I $(srctree)/usr/dummy-include # The following are excluded for now because they fail to build. #
Signature · 1 line
2.32.0
Re: [PATCH 2/2] kbuild: forbid exported headers from including <stdint.h>, <stdbool.h>
Quoted 26 lines · Masahiro Yamada
Some UAPI headers included <
stdlib.h>, like this:#ifndef __KERNEL__ #include <stdlib.h> #endifAs it turned out, they just included it for no good reason.
After some fixes, now I can compile-test UAPI headers (
CONFIG_UAPI_HEADER_TEST=y) without <stdlib.h> included.To avoid somebody getting it back again, this commit adds the dummy header,
usr/dummy-include/stdlib.hI added $(srctree)/usr/dummy-include to the header search paths. Because it is searched before the system directories, if someone tries to include <
stdlib.h>, they will see the error message.While I am here, I also replaced $(objtree)/usr/include with $(obj), but it is just a small refactoring.
If we achieve the situation where none of system headers is included from exported kernel headers (i.e. kernel headers become self-contained), we might be able to add -nostdinc, but that is much far from where we stand now. (see many no-header-test lines in
usr/include/Makefile)
Quoted 7 lines
As a realistic solution, you can forbid header inclusion individually by putting a dummy header into
usr/dummy-include/.Currently, no header include <
stdbool.h>. I put it as well before somebody attempts to use it.Signed-off-by Masahiro Yamada <[email protected]>
Nice work!
Re: [PATCH 2/2] kbuild: forbid exported headers from including <stdint.h>, <stdbool.h>
Quoted 31 lines · Greg Kroah-Hartman
Quoted 29 lines · Masahiro Yamada
Some UAPI headers included <
stdlib.h>, like this:#ifndef __KERNEL__ #include <stdlib.h> #endifAs it turned out, they just included it for no good reason.
After some fixes, now I can compile-test UAPI headers (
CONFIG_UAPI_HEADER_TEST=y) without <stdlib.h> included.To avoid somebody getting it back again, this commit adds the dummy header,
usr/dummy-include/stdlib.hI added $(srctree)/usr/dummy-include to the header search paths. Because it is searched before the system directories, if someone tries to include <
stdlib.h>, they will see the error message.While I am here, I also replaced $(objtree)/usr/include with $(obj), but it is just a small refactoring.
If we achieve the situation where none of system headers is included from exported kernel headers (i.e. kernel headers become self-contained), we might be able to add -nostdinc, but that is much far from where we stand now. (see many no-header-test lines in
usr/include/Makefile)As a realistic solution, you can forbid header inclusion individually by putting a dummy header into
usr/dummy-include/.
Quoted 8 lines
Quoted 4 lines
Currently, no header include <
stdbool.h>. I put it as well before somebody attempts to use it.Signed-off-by Masahiro Yamada <[email protected]>Nice work!
Reviewed-by Greg Kroah-Hartman <[email protected]>
I made a mistake in the patch subject.
The correct title should be:
kbuild: forbid exported headers from including <stdlib.h>, <stdbool.h>
I will fix it in v2.
We cannot ban <stdint.h> for now because there are still some users.
A fix-up patch exists, but the fuse maintainer was opposed to it.
https://lore.kernel.org/lkml/[email protected]/
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 2/2] kbuild: forbid exported headers from including <stdint.h>, <stdbool.h>
Quoted 43 lines · Masahiro Yamada
Quoted 31 lines · Greg Kroah-Hartman
Quoted 29 lines · Masahiro Yamada
Some UAPI headers included <
stdlib.h>, like this:#ifndef __KERNEL__ #include <stdlib.h> #endifAs it turned out, they just included it for no good reason.
After some fixes, now I can compile-test UAPI headers (
CONFIG_UAPI_HEADER_TEST=y) without <stdlib.h> included.To avoid somebody getting it back again, this commit adds the dummy header,
usr/dummy-include/stdlib.hI added $(srctree)/usr/dummy-include to the header search paths. Because it is searched before the system directories, if someone tries to include <
stdlib.h>, they will see the error message.While I am here, I also replaced $(objtree)/usr/include with $(obj), but it is just a small refactoring.
If we achieve the situation where none of system headers is included from exported kernel headers (i.e. kernel headers become self-contained), we might be able to add -nostdinc, but that is much far from where we stand now. (see many no-header-test lines in
usr/include/Makefile)As a realistic solution, you can forbid header inclusion individually by putting a dummy header into
usr/dummy-include/.Quoted 8 lines
Quoted 4 lines
Currently, no header include <
stdbool.h>. I put it as well before somebody attempts to use it.Signed-off-by Masahiro Yamada <[email protected]>Nice work!
Reviewed-by Greg Kroah-Hartman <[email protected]>
Quoted 7 lines
I made a mistake in the patch subject.
The correct title should be:
kbuild: forbid exported headers from including <
stdlib.h>, <stdbool.h>I will fix it in v2.
Ah, missed that, yes.
Quoted 4 lines
We cannot ban <
stdint.h> for now because there are still some users.A fix-up patch exists, but the fuse maintainer was opposed to it.
https://lore.kernel.org/lkml/[email protected]/
It's not ok for one lone file to break the rules that all other uapi header files follow. I think that needs to be fixed, there is NOTHING special about that one subsystem to justify this.
Uniformity is good, and should be followed, and I strongly think that change needs to be accepted.
thanks,
greg k-h