We already got rid of this dependency for the normal barebox build, so
break it up for the scripts/ build as well to avoid this nconf warning
on some distros:

  In file included from scripts/kconfig/nconf.c:15:
  scripts/kconfig/nconf.h:25:9: warning: ‘max’ redefined
     25 | #define max(a, b) ({\
        |         ^~~
  In file included from ./barebox/scripts/include/linux/list.h:5,
                   from ./barebox/scripts/include/list.h:5,
                   from scripts/kconfig/expr.h:15,
                   from scripts/kconfig/lkc.h:13,
                   from scripts/kconfig/nconf.c:14:
  ./barebox/scripts/include/linux/kernel.h:39:9: note: this is the location of 
the previous definition
     39 | #define max(x, y) ({                            \
        |         ^~~
  scripts/kconfig/nconf.h:30:9: warning: ‘min’ redefined

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 scripts/include/linux/container_of.h | 18 ++++++++++++++++++
 scripts/include/linux/kernel.h       | 14 +-------------
 scripts/include/linux/list.h         |  2 +-
 3 files changed, 20 insertions(+), 14 deletions(-)
 create mode 100644 scripts/include/linux/container_of.h

diff --git a/scripts/include/linux/container_of.h 
b/scripts/include/linux/container_of.h
new file mode 100644
index 000000000000..ca0ec95667b9
--- /dev/null
+++ b/scripts/include/linux/container_of.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SCRIPTS_LINUX_CONTAINER_OF_H
+#define _SCRIPTS_LINUX_CONTAINER_OF_H
+
+#ifndef container_of
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:       the pointer to the member.
+ * @type:      the type of the container struct this is embedded in.
+ * @member:    the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({                     \
+       const typeof(((type *)0)->member) * __mptr = (ptr);     \
+       (type *)((char *)__mptr - offsetof(type, member)); })
+#endif
+
+#endif /* _SCRIPTS_LINUX_CONTAINER_OF_H */
diff --git a/scripts/include/linux/kernel.h b/scripts/include/linux/kernel.h
index f3083ff3545d..672f681931ec 100644
--- a/scripts/include/linux/kernel.h
+++ b/scripts/include/linux/kernel.h
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <linux/container_of.h>
 
 #define __ALIGN_MASK(x, mask)  (((x) + (mask)) & ~(mask))
 #define ALIGN(x, a)            __ALIGN_MASK(x, (typeof(x))(a) - 1)
@@ -20,19 +21,6 @@
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
 
-#ifndef container_of
-/**
- * container_of - cast a member of a structure out to the containing structure
- * @ptr:       the pointer to the member.
- * @type:      the type of the container struct this is embedded in.
- * @member:    the name of the member within the struct.
- *
- */
-#define container_of(ptr, type, member) ({                     \
-       const typeof(((type *)0)->member) * __mptr = (ptr);     \
-       (type *)((char *)__mptr - offsetof(type, member)); })
-#endif
-
 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 
 #ifndef max
diff --git a/scripts/include/linux/list.h b/scripts/include/linux/list.h
index d6b24f6b744d..d10e44469974 100644
--- a/scripts/include/linux/list.h
+++ b/scripts/include/linux/list.h
@@ -2,8 +2,8 @@
 #define __TOOLS_LINUX_LIST_H
 
 #include <linux/types.h>
-#include <linux/kernel.h>
 #include <linux/compiler.h>
+#include <linux/container_of.h>
 
 /*
  * Simple doubly linked list implementation.
-- 
2.47.3


Reply via email to