Skip to contentSkip to conversation

drm/print: Include drm_device.h

PATCH Applied Gustavo Sousa 4 participants 8 messages Jan 21, 2025 – Jan 25, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/print: Include drm_device.h

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

---
 include/drm/drm_print.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/drm_print.h +1 -0
index f77fe1531cf8..9732f514566d 100644
@@ -32,6 +32,7 @@
 #include <linux/dynamic_debug.h>
 
 #include <drm/drm.h>
+#include <drm/drm_device.h>
 
 struct debugfs_regset32;
 struct drm_device;
Signature · 1 line
2.48.1
#1 lore raw
Quoted 18 lines · Gustavo Sousa

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

---
 include/drm/drm_print.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/drm_print.h +0 -0
index f77fe1531cf8..9732f514566d 100644

include/drm/drm_print.h line 35

Quoted 4 lines
include/drm/drm_print.h +1 -0
@@ -32,6 +32,7 @@
 #include <linux/dynamic_debug.h>
 
 #include <drm/drm.h>
+#include <drm/drm_device.h>

We much prefer just a struct device forward decl to avoid monster headers. Is that not doable here? Worst case I'd convert the drm_info_printer() static inline to a macro, not sure about the exact rules here if you never deref a pointer.
-Sima

Quoted 6 lines
include/drm/drm_print.h +0 -0
 struct debugfs_regset32;
 struct drm_device;
Signature · 1 line
2.48.1
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#2 lore raw

Quoting Simona Vetter (2025-01-22 08:11:53-03:00)

Quoted 21 lines · Gustavo Sousa
Quoted 20 lines

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

---
 include/drm/drm_print.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/drm_print.h +0 -0
index f77fe1531cf8..9732f514566d 100644
@@ -32,6 +32,7 @@
 #include <linux/dynamic_debug.h>
 
Quoted 5 lines

include/drm/drm_print.h line 35

Quoted 2 lines
include/drm/drm_print.h +1 -0
 #include <drm/drm.h>
+#include <drm/drm_device.h>

We much prefer just a struct device forward decl to avoid monster headers. Is that not doable here?

I don't think so. This header explicitly uses members of struct drm_device, so the compiler needs to know the full type definition. As an example see the definition of drm_WARN(), it uses (drm)->dev.

--
Gustavo Sousa

Quoted 16 lines

Worst case I'd convert the drm_info_printer()
static inline to a macro, not sure about the exact rules here if you never deref a pointer.
-Sima

Quoted 6 lines
include/drm/drm_print.h +0 -0
 struct debugfs_regset32;
 struct drm_device;
Signature · 1 line
2.48.1
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#3 lore raw
Quoted 28 lines · Gustavo Sousa

Quoting Simona Vetter (2025-01-22 08:11:53-03:00)

Quoted 21 lines · Gustavo Sousa
Quoted 20 lines

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

---
 include/drm/drm_print.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/drm_print.h +0 -0
index f77fe1531cf8..9732f514566d 100644
@@ -32,6 +32,7 @@
 #include <linux/dynamic_debug.h>
 
Quoted 5 lines

include/drm/drm_print.h line 35

Quoted 2 lines
include/drm/drm_print.h +1 -0
 #include <drm/drm.h>
+#include <drm/drm_device.h>

We much prefer just a struct device forward decl to avoid monster headers. Is that not doable here?

Quoted 3 lines

I don't think so. This header explicitly uses members of struct drm_device, so the compiler needs to know the full type definition. As an example see the definition of drm_WARN(), it uses (drm)->dev.

I grudgingly agree. I don't think there are actual cases where this happens, but I can imagine you could create one.

Quoted 3 lines
Quoted 3 lines

Worst case I'd convert the drm_info_printer() static inline to a macro, not sure about the exact rules here if you never deref a pointer.

The forward declaration is enough for passing pointers around without dereferencing. It's the dereferencing in the macros that could fail the build if the .c using them doesn't include drm_device.h.

To balance things out, I think we could probably drop drm/drm.h if we inlined one use of DRM_NAME to just "drm".

BR,
Jani.

Quoted 13 lines
Quoted 13 lines

-Sima

Quoted 6 lines
include/drm/drm_print.h +0 -0
 struct debugfs_regset32;
 struct drm_device;
Signature · 1 line
2.48.1
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 1 line
Jani Nikula, Intel
#4 lore raw

Quoting Jani Nikula (2025-01-22 11:02:31-03:00)

Quoted 29 lines · Gustavo Sousa
Quoted 28 lines

Quoting Simona Vetter (2025-01-22 08:11:53-03:00)

Quoted 26 lines · Gustavo Sousa
Quoted 18 lines

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

---
 include/drm/drm_print.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/drm_print.h +0 -0
index f77fe1531cf8..9732f514566d 100644

include/drm/drm_print.h line 35

Quoted 4 lines
include/drm/drm_print.h +1 -0
@@ -32,6 +32,7 @@
 #include <linux/dynamic_debug.h>
 
 #include <drm/drm.h>
+#include <drm/drm_device.h>

We much prefer just a struct device forward decl to avoid monster headers. Is that not doable here?

Quoted 6 lines
Quoted 3 lines

I don't think so. This header explicitly uses members of struct drm_device, so the compiler needs to know the full type definition. As an example see the definition of drm_WARN(), it uses (drm)->dev.

I grudgingly agree. I don't think there are actual cases where this happens, but I can imagine you could create one.

It happened to me, and that motivated me to send this patch.

I had a local patch where I just needed the drm_print.h header, but I ended up having to include drm_device.h in my .c file.

Quoted 33 lines
Quoted 4 lines
Quoted 4 lines

Worst case I'd convert the drm_info_printer() static inline to a macro, not sure about the exact rules here if you never deref a pointer.

The forward declaration is enough for passing pointers around without dereferencing. It's the dereferencing in the macros that could fail the build if the .c using them doesn't include drm_device.h.

To balance things out, I think we could probably drop drm/drm.h if we inlined one use of DRM_NAME to just "drm".

BR,
Jani.

Quoted 13 lines
Quoted 13 lines

-Sima

Quoted 6 lines
include/drm/drm_print.h +0 -0
 struct debugfs_regset32;
 struct drm_device;
Signature · 1 line
2.48.1
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 1 line
Jani Nikula, Intel
Reviewed-by
#5 lore raw
Quoted 34 lines · Gustavo Sousa

Quoting Jani Nikula (2025-01-22 11:02:31-03:00)

Quoted 33 lines · Gustavo Sousa
Quoted 31 lines

Quoting Simona Vetter (2025-01-22 08:11:53-03:00)

Quoted 21 lines · Gustavo Sousa
Quoted 20 lines

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

---
 include/drm/drm_print.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/drm_print.h +0 -0
index f77fe1531cf8..9732f514566d 100644
@@ -32,6 +32,7 @@
 #include <linux/dynamic_debug.h>
 
Quoted 5 lines

include/drm/drm_print.h line 35

Quoted 2 lines
include/drm/drm_print.h +1 -0
 #include <drm/drm.h>
+#include <drm/drm_device.h>

We much prefer just a struct device forward decl to avoid monster headers. Is that not doable here?

I don't think so. This header explicitly uses members of struct drm_device, so the compiler needs to know the full type definition. As an example see the definition of drm_WARN(), it uses (drm)->dev.

Quoted 7 lines
Quoted 2 lines

I grudgingly agree. I don't think there are actual cases where this happens, but I can imagine you could create one.

It happened to me, and that motivated me to send this patch.

I had a local patch where I just needed the drm_print.h header, but I ended up having to include drm_device.h in my .c file.

Right.

Quoted 34 lines
Quoted 34 lines
Quoted 5 lines
Quoted 5 lines

Worst case I'd convert the drm_info_printer() static inline to a macro, not sure about the exact rules here if you never deref a pointer.

The forward declaration is enough for passing pointers around without dereferencing. It's the dereferencing in the macros that could fail the build if the .c using them doesn't include drm_device.h.

To balance things out, I think we could probably drop drm/drm.h if we inlined one use of DRM_NAME to just "drm".

BR,
Jani.

Quoted 13 lines
Quoted 13 lines

-Sima

Quoted 6 lines
include/drm/drm_print.h +0 -0
 struct debugfs_regset32;
 struct drm_device;
Signature · 1 line
2.48.1
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 1 line
Jani Nikula, Intel
Signature · 1 line
Jani Nikula, Intel
#6 lore raw
Quoted 38 lines · Jani Nikula
Quoted 37 lines · Gustavo Sousa

Quoting Jani Nikula (2025-01-22 11:02:31-03:00)

Quoted 35 lines · Gustavo Sousa
Quoted 28 lines

Quoting Simona Vetter (2025-01-22 08:11:53-03:00)

Quoted 21 lines · Gustavo Sousa
Quoted 20 lines

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

---
 include/drm/drm_print.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/drm_print.h +0 -0
index f77fe1531cf8..9732f514566d 100644
@@ -32,6 +32,7 @@
 #include <linux/dynamic_debug.h>
 
Quoted 5 lines

include/drm/drm_print.h line 35

Quoted 2 lines
include/drm/drm_print.h +1 -0
 #include <drm/drm.h>
+#include <drm/drm_device.h>

We much prefer just a struct device forward decl to avoid monster headers. Is that not doable here?

Quoted 3 lines

I don't think so. This header explicitly uses members of struct drm_device, so the compiler needs to know the full type definition. As an example see the definition of drm_WARN(), it uses (drm)->dev.

I grudgingly agree. I don't think there are actual cases where this happens, but I can imagine you could create one.

Quoted 8 lines
Quoted 4 lines

It happened to me, and that motivated me to send this patch.

I had a local patch where I just needed the drm_print.h header, but I ended up having to include drm_device.h in my .c file.

Right.

So at least in the past we sometimes intentionally used macros instead of static inline functions, so that we could avoid pulling in headers from headers all over the place. That's why I only looked at the one static inline functions, which treats the pointer as opaque so should work.

I don't mind either way, just bringing this in so that we're consistent here.
-Sima

Quoted 38 lines
Quoted 35 lines
Quoted 35 lines
Quoted 6 lines
Quoted 6 lines

Worst case I'd convert the drm_info_printer() static inline to a macro, not sure about the exact rules here if you never deref a pointer.

The forward declaration is enough for passing pointers around without dereferencing. It's the dereferencing in the macros that could fail the build if the .c using them doesn't include drm_device.h.

To balance things out, I think we could probably drop drm/drm.h if we inlined one use of DRM_NAME to just "drm".

BR,
Jani.

Quoted 13 lines
Quoted 13 lines

-Sima

Quoted 6 lines
include/drm/drm_print.h +0 -0
 struct debugfs_regset32;
 struct drm_device;
Signature · 1 line
2.48.1
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 1 line
Jani Nikula, Intel
Signature · 1 line
Jani Nikula, Intel
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#7 lore raw
In reply to Gustavo Sousa
Quoted 9 lines · Gustavo Sousa

The header drm_print.h uses members of struct drm_device pointers, as such, it should include drm_device.h to let the compiler know the full type definition.

Without such include, users of drm_print.h that don't explicitly need drm_device.h would bump into build errors and be forced to include the latter.

[...]

Applied to drm-misc-fixes, thanks!

[1/1] drm/print: Include drm_device.h

      commit: e0f63bc68f59d281e2d06e596f6c1bd9382a15cd

Best regards,

Signature · 1 line
Lucas De Marchi <[email protected]>