[PATCH 1/2][next] stddef: Remove token-pasting in TRAILING_OVERLAP()

Gustavo A. R. Silva posted 2 patches 2 weeks ago
[PATCH 1/2][next] stddef: Remove token-pasting in TRAILING_OVERLAP()
Posted by Gustavo A. R. Silva 2 weeks ago
Currently, TRAILING_OVERLAP() token-pastes the FAM parameter into the
name of internal pdding member `__offset_to_##FAM`. This forces FAM to
be a single identifier, which prevents callers from using a FAM when
it's a nested member. For instance, see the following scenario:

| struct flex {
| 	size_t count;
| 	int data[];
| };

| struct foo {
| 	int hdr_foo;
| 	struct flex f;
| };

| struct composite {
| 	struct foo hdr;
| 	int data[100];
| };

In this case, it'd be useful if TRAILING_OVERLAP() could be used in
the following way:

| struct composite {
| 	TRAILING_OVERLAP(struct foo, hdr, f.data,
| 		int data[100];
| 	);
| };

However, this is not current possible due to the token concatenation
in `__offset_to_##FAM`, which fails when FAM contains a dot.

So, remove token-pasting and use the fixed internal name
`__offset_to_FAM` and, with this, expand the capabilities of
TRAILING_OVERLAP(). :)

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 include/linux/stddef.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index dab49e2ec8c0..701099c67c24 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -108,7 +108,7 @@ enum {
 	union {									\
 		TYPE NAME;							\
 		struct {							\
-			unsigned char __offset_to_##FAM[offsetof(TYPE, FAM)];	\
+			unsigned char __offset_to_FAM[offsetof(TYPE, FAM)];	\
 			MEMBERS							\
 		};								\
 	}
-- 
2.43.0