lkml.org 
[lkml]   [2021]   [Nov]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
SubjectRe: [PATCH v2 01/20] linux/stddef.h, linux/offsetof.h: Split offsetof() into a separate header
From
Hi Andy,

On 11/20/21 17:14, Andy Shevchenko wrote:
> On Sat, Nov 20, 2021 at 3:02 PM Alejandro Colomar
> <alx.manpages@gmail.com> wrote:
>>
>> Include <linux/offsetof.h> from <linux/stddef.h> for compatibility.
>>
>> From <linux/offsetof.h>:
>> Include the same exact deps that <linux/stddef.h> had.
>> Changing that in any way broke my compilation.
>
> The commit message does not explain why you are doing this, what's the
> problem it fixes.
>

Hmm, yes, after many attempts,
that one doesn't fix anything.
I think I should drop the split of offsetof[end](),
since I'm forced to include the same headers indirectly anyway.


For the rest,
such as sizeof_field(),
I'm allowed to include just a tiny header with the definition
in the following cases:

a91eb933173e tools/virtio/: Don't redefine container_of()
836786f021cc tools/usb/: Don't redefine container_of()
f51e3d656990 tools/testing/selftests/rcutorture/: Don't redefine
container_of()
99aa6a86fb21 samples/bpf/: Don't redefine container_of()
0463de8c8e86 tools/testing/selftests/vm/: Don't redefine ARRAY_SIZE()
9cda268b981d tools/testing/selftests/timens/: Don't redefine ARRAY_SIZE()
02efb34c1afa tools/testing/selftests/sparc/: Don't redefine ARRAY_SIZE()
4973f19407f0 tools/testing/selftests/seccomp/: Don't redefine ARRAY_SIZE()
ecaee90a1b3c tools/testing/selftests/rseq/: Don't redefine ARRAY_SIZE()
2392de0d71f2 tools/testing/selftests/openat2/: Don't redefine ARRAY_SIZE()
bbc657cb231d tools/testing/selftests/net/: Don't redefine ARRAY_SIZE()
f5eae2dee077 tools/testing/selftests/landlock/: Don't redefine ARRAY_SIZE()
c35ca31451ef tools/testing/selftests/kselftest_harness.h: Don't redefine
ARRAY_SIZE()
76fce3e8f3bd tools/testing/selftests/ir/: Don't redefine ARRAY_SIZE()
4f7f4632effd tools/testing/selftests/core/: Don't redefine ARRAY_SIZE()
71352d2db882 tools/testing/selftests/cgroup/: Don't redefine ARRAY_SIZE()
d2f0dc48706b tools/testing/selftests/bpf/: Don't redefine ARRAY_SIZE()
11760b380c35 tools/testing/selftests/arm64/: Don't redefine ARRAY_SIZE()
ea04d7799b42 tools/vm/: Don't redefine ARRAY_SIZE()
d5e54883d374 tools/virtio/: Don't redefine ARRAY_SIZE()
ab4f6b9fb71b tools/usb/: Don't redefine ARRAY_SIZE()
dfa264d3150d tools/spi/: Don't redefine ARRAY_SIZE()
0513d57ad00e tools/power/: Don't redefine ARRAY_SIZE()
418a8fa44788 tools/lib/traceevent/: Don't redefine ARRAY_SIZE()
bb9b11f95249 tools/iio/: Don't redefine ARRAY_SIZE()
3350c5b02479 tools/gpio/: Don't redefine ARRAY_SIZE()
dab0e175d727 tools/firewire/: Don't redefine ARRAY_SIZE()
a7457639b307 tools/bpf/: Don't redefine ARRAY_SIZE()
c651930196f1 tools/arch/: Don't redefine ARRAY_SIZE()
a2ba541db10c samples/seccomp/: Don't redefine ARRAY_SIZE()
ed5609ed8785 samples/bpf/: Don't redefine ARRAY_SIZE()
9b568cd21579 lib/zstd/: Don't redefine ARRAY_SIZE()
4f2d185b6ccc lib/mpi/: Don't redefine ARRAY_SIZE()
a14b402ce8dc include/acpi/: Don't redefine ARRAY_SIZE()
34dc6551c0a4 fs/unicode/: Don't redefine ARRAY_SIZE()
7ac3580d0d03 fs/orangefs/: Don't redefine ARRAY_SIZE()
9ff567cbf6d3 drivers/net/ethernet/: Don't redefine ARRAY_SIZE()
a8c503ade00a arch/um/: Don't redefine ARRAY_SIZE()
b5ffd6f335d2 arch/powerpc/: Don't redefine ARRAY_SIZE()
f5acf6fd58b1 arch/mips/: Don't redefine ARRAY_SIZE()
78347d718990 tools/testing/selftests/bpf/: Don't redefine NULL
d6ecbed02c1c include/acpi/: Don't redefine NULL
f6bd9b2ddfa2 drivers/video/: Don't redefine NULL
f9b15eccf7ba drivers/net/: Don't redefine NULL
eb07b8abb7b9 drivers/media/: Don't redefine NULL
f3e8e2322350 crypto/: Don't redefine NULL
888c3a451ba1 arch/parisc/: Don't redefine NULL
95a5dd02310d arch/mips/: Don't redefine NULL
0e1f3fb47007 tools/testing/selftests/bpf/: Don't redefine sizeof_field()
ddfa13d5dd76 tools/testing/selftests/bpf/: Don't redefine offsetofend()
bd393bf9fd41 tools/usb/: Don't redefine offsetof()
fd17a1d549f1 tools/testing/selftests/bpf/: Don't redefine offsetof()
f32aed18c34d samples/bpf/: Don't redefine offsetof()
b2755f698986 drivers/staging/: Don't redefine offsetof()


That is the draft that I have for patch set 2.

As an example, let me show you one of those commits:

$ git show 0e1f3fb47007
commit 0e1f3fb47007ca93df6f2b998868c892258e6ea9
Author: Alejandro Colomar <alx.manpages@gmail.com>
Date: Fri Nov 19 18:28:30 2021 +0100

tools/testing/selftests/bpf/: Don't redefine sizeof_field()

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>

diff --git a/tools/testing/selftests/bpf/bpf_util.h
b/tools/testing/selftests/bpf/bpf_util.h
index 28c29292bacd..394377e4aa14 100644
--- a/tools/testing/selftests/bpf/bpf_util.h
+++ b/tools/testing/selftests/bpf/bpf_util.h
@@ -8,6 +8,7 @@
#include <errno.h>
#include <bpf/libbpf.h> /* libbpf_num_possible_cpus */
#include <linux/offsetofend.h>
+#include <linux/sizeof_field.h>

static inline unsigned int bpf_num_possible_cpus(void)
{
@@ -32,9 +33,5 @@ static inline unsigned int bpf_num_possible_cpus(void)
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

-#ifndef sizeof_field
-#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
-#endif
-

#endif /* __BPF_UTIL__ */
diff --git a/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
b/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
index 5f4e87ee949a..5fafb54910cd 100644
--- a/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
+++ b/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
@@ -6,6 +6,7 @@
#include <stdbool.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <linux/sizeof_field.h>
#include <linux/tcp.h>
#include <linux/socket.h>
#include <linux/bpf.h>
@@ -15,9 +16,6 @@
#define BPF_PROG_TEST_TCP_HDR_OPTIONS
#include "test_tcp_hdr_options.h"

-#ifndef sizeof_field
-#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
-#endif

__u8 test_kind = TCPOPT_EXP;
__u16 test_magic = 0xeB9F;

--
Alejandro Colomar
Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

\
 
 \ /
  Last update: 2021-11-20 17:23    [W:0.864 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site