Skip to contentSkip to conversation

xen/bitmap: Drop unused headers

PATCH In review Andrew Cooper 3 participants 3 messages May 10, 2025 – Feb 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/bitmap: Drop unused headers

Nothing in bitmap.h uses lib.h. Reduce to just macros.h and string.h. Drop types.h while at it, as it comes in through bitops.h

cpumask.h and nodemask.h only include kernel.h to get container_of(). Move it into macros.h where it belongs.

No functional change.

---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>

https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/1810741296

v2:
* Rebase by a year.
* Move container_of() too.

---
 xen/include/xen/bitmap.h   |  4 ++--
 xen/include/xen/cpumask.h  |  1 -
 xen/include/xen/kernel.h   | 12 ------------
 xen/include/xen/macros.h   | 13 +++++++++++++
 xen/include/xen/nodemask.h |  1 -
 5 files changed, 15 insertions(+), 16 deletions(-)
xen/include/xen/bitmap.h +2 -2
index b5e9cdd3db86..79b2cd171595 100644
@@ -3,9 +3,9 @@
 
 #ifndef __ASSEMBLY__
 
-#include <xen/lib.h>
-#include <xen/types.h>
 #include <xen/bitops.h>
+#include <xen/macros.h>
+#include <xen/string.h>
 
 /*
  * bitmaps provide bit arrays that consume one or more unsigned
xen/include/xen/cpumask.h +0 -1
index b713bb69a9cb..a7715dfa0308 100644
@@ -57,7 +57,6 @@
 
 #include <xen/bitmap.h>
 #include <xen/bug.h>
-#include <xen/kernel.h>
 #include <xen/random.h>
 
 typedef struct cpumask{ DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
xen/include/xen/kernel.h +0 -12
index c5b6cc977772..378f21c247a6 100644
@@ -8,18 +8,6 @@
 #include <xen/macros.h>
 #include <xen/types.h>
 
-/**
- * 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) ({                      \
-        typeof_field(type, member) *__mptr = (ptr);             \
-        (type *)( (char *)__mptr - offsetof(type,member) );})
-
 /**
  * __struct_group() - Create a mirrored named and anonyomous struct
  *
xen/include/xen/macros.h +13 -0
index cd528fbdb127..58affb1588c5 100644
@@ -102,6 +102,19 @@
  */
 #define sizeof_field(type, member) sizeof(((type *)NULL)->member)
 
+/**
+ * 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)                         \
+    ({                                                          \
+        typeof_field(type, member) *__mptr = (ptr);             \
+        (type *)((void *)__mptr - offsetof(type, member));      \
+    })
+
 /* Cast an arbitrary integer to a pointer. */
 #define _p(x) ((void *)(unsigned long)(x))
 
xen/include/xen/nodemask.h +0 -1
index 1dd6c7458e77..60d6455feb8b 100644
@@ -53,7 +53,6 @@
  * for_each_online_node(node)		for-loop node over node_online_map
  */
 
-#include <xen/kernel.h>
 #include <xen/bitmap.h>
 #include <xen/numa.h>
 
Signature · 1 line
2.39.5
Acked-by on v1 1/1
#1 lore raw

Hi Andrew,

Quoted 5 lines · Andrew Cooper

Nothing in bitmap.h uses lib.h. Reduce to just macros.h and string.h. Drop types.h while at it, as it comes in through bitops.h

cpumask.h and nodemask.h only include kernel.h to get container_of(). Move it into macros.h where it belongs.

The wording implies that container_of() will be moved as-is (barring coding style). However...

[...]

xen/include/xen/kernel.h line 22

Quoted 12 lines
xen/include/xen/kernel.h +0 -12
-/**
- * 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) ({                      \
-        typeof_field(type, member) *__mptr = (ptr);             \
-        (type *)( (char *)__mptr - offsetof(type,member) );})
-

I see the cast was switch from "char *" to ...

Quoted 12 lines

/**
* __struct_group() - Create a mirrored named and anonyomous struct *

xen/include/xen/macros.h +1 -0
index cd528fbdb127..58affb1588c5 100644
@@ -102,6 +102,19 @@
   */
  #define sizeof_field(type, member) sizeof(((type *)NULL)->member)
 
+/**

xen/include/xen/macros.h line 115

Quoted 10 lines
xen/include/xen/macros.h +10 -0
+ * 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)                         \
+    ({                                                          \
+        typeof_field(type, member) *__mptr = (ptr);             \
+        (type *)((void *)__mptr - offsetof(type, member));      \

... "void *". AFAICT, this is doesn't change anything. However, I think it is worth mentioning in the commit message to show this was intended.

With that:

Cheers,

Signature · 1 line
Julien Grall