Skip to contentSkip to conversation

drm/ioctl: turn on -Woverride-init for IOCTL table

PATCH In review Simon Ser 2 participants 2 messages Jul 20, 2023 – Jul 31, 2023

Subsystems (2)
lore
Share & tools
lore

Simon Ser

author
#0 lore raw

PATCH 1/1 drm/ioctl: turn on -Woverride-init for IOCTL table

Recently two patches [1] [2] have hit a case of mistakenly picking an IOCTL number which was already in-use. This is hard to debug because the last definition wins and there is no indication that there is a conflict.

Fix this by enabling -Werror=override-init for the IOCTL table. When there is a duplicate entry, the compiler now errors out:

CC [M] drivers/gpu/drm/drm_ioctl.o
drivers/gpu/drm/drm_ioctl.c:555:33: error: initialized field overwritten [-Werror=override-init]
555 | [DRM_IOCTL_NR(ioctl)] = { \
| ^
drivers/gpu/drm/drm_ioctl.c:708:9: note: in expansion of macro ‘DRM_IOCTL_DEF’
708 | DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_EVENTFD, drm_syncobj_reset_ioctl,
| ^~~~~~~~~~~~~
drivers/gpu/drm/drm_ioctl.c:555:33: note: (near initialization for ‘drm_ioctls[207]’)
555 | [DRM_IOCTL_NR(ioctl)] = { \
| ^
drivers/gpu/drm/drm_ioctl.c:708:9: note: in expansion of macro ‘DRM_IOCTL_DEF’
708 | DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_EVENTFD, drm_syncobj_reset_ioctl,
| ^~~~~~~~~~~~~
cc1: some warnings being treated as errors

[1]: https://lore.kernel.org/dri-devel/[email protected]/
[2]: https://lore.kernel.org/dri-devel/vVFDBgHpdcB0vOwnl02QPOFmAZPEbIV56E_wQ8B012K2GZ-fAGyG0JMbSrMu3-IcKYVf0JpJyrf71e6KFHfeMoSPJlYRACxlxy91eW9c6Fc=@emersion.fr/

Cc Erik Kurzinger <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc Christian König <[email protected]>
---
 drivers/gpu/drm/drm_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_ioctl.c +3 -0
index f03ffbacfe9b..cd485eb54d2a 100644
@@ -566,6 +566,8 @@ static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
 #endif
 
 /* Ioctl table */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Woverride-init"
 static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
@@ -718,6 +720,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER),
 };
+#pragma GCC diagnostic pop
 
 #define DRM_CORE_IOCTL_COUNT	ARRAY_SIZE(drm_ioctls)
 
Signature · 1 line
2.41.0
#1 lore raw
Quoted 40 lines · Simon Ser

Recently two patches [1] [2] have hit a case of mistakenly picking an IOCTL number which was already in-use. This is hard to debug because the last definition wins and there is no indication that there is a conflict.

Fix this by enabling -Werror=override-init for the IOCTL table. When there is a duplicate entry, the compiler now errors out:

CC [M] drivers/gpu/drm/drm_ioctl.o
drivers/gpu/drm/drm_ioctl.c:555:33: error: initialized field overwritten [-Werror=override-init]
555 | [DRM_IOCTL_NR(ioctl)] = { \
| ^
drivers/gpu/drm/drm_ioctl.c:708:9: note: in expansion of macro ‘DRM_IOCTL_DEF’
708 | DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_EVENTFD, drm_syncobj_reset_ioctl,
| ^~~~~~~~~~~~~
drivers/gpu/drm/drm_ioctl.c:555:33: note: (near initialization for ‘drm_ioctls[207]’)
555 | [DRM_IOCTL_NR(ioctl)] = { \
| ^
drivers/gpu/drm/drm_ioctl.c:708:9: note: in expansion of macro ‘DRM_IOCTL_DEF’
708 | DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_EVENTFD, drm_syncobj_reset_ioctl,
| ^~~~~~~~~~~~~
cc1: some warnings being treated as errors

[1]: https://lore.kernel.org/dri-devel/[email protected]/
[2]: https://lore.kernel.org/dri-devel/vVFDBgHpdcB0vOwnl02QPOFmAZPEbIV56E_wQ8B012K2GZ-fAGyG0JMbSrMu3-IcKYVf0JpJyrf71e6KFHfeMoSPJlYRACxlxy91eW9c6Fc=@emersion.fr/

Cc Erik Kurzinger <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc Christian König <[email protected]>
---
 drivers/gpu/drm/drm_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_ioctl.c +0 -0
index f03ffbacfe9b..cd485eb54d2a 100644

drivers/gpu/drm/drm_ioctl.c static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv) · line 570

Quoted 5 lines
drivers/gpu/drm/drm_ioctl.c +2 -0
@@ -566,6 +566,8 @@ static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
 #endif
 
 /* Ioctl table */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Woverride-init"

You should probably use __diag_push(), __diag_warn(), and __diag_pop() compiler agnostic wrappers instead of using #pragmas directly.

BR,
Jani.

Quoted 10 lines
drivers/gpu/drm/drm_ioctl.c +1 -0
 static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
@@ -718,6 +720,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER),
 };
+#pragma GCC diagnostic pop
 
 #define DRM_CORE_IOCTL_COUNT	ARRAY_SIZE(drm_ioctls)
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center