[PATCH 1/2] drm/imagination: Move all FW interface check macros to pvr_checks.h

From: Alessio Belle

Date: Wed Jul 29 2026 - 11:52:17 EST


From: Alexandru Dadu <alexandru.dadu@xxxxxxxxxx>

The same macros are redefined in three places, so move them to a common
file to reduce duplication and make it easier to reuse them.

Signed-off-by: Alexandru Dadu <alexandru.dadu@xxxxxxxxxx>
Co-developed-by: Alessio Belle <alessio.belle@xxxxxxxxxx>
Signed-off-by: Alessio Belle <alessio.belle@xxxxxxxxxx>
---
drivers/gpu/drm/imagination/pvr_check.h | 36 ++++++++++++++++++++++
drivers/gpu/drm/imagination/pvr_rogue_fwif_check.h | 26 +---------------
.../drm/imagination/pvr_rogue_fwif_client_check.h | 9 +-----
.../drm/imagination/pvr_rogue_fwif_shared_check.h | 9 +-----
4 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/drivers/gpu/drm/imagination/pvr_check.h b/drivers/gpu/drm/imagination/pvr_check.h
new file mode 100644
index 000000000000..94764ce9bbd1
--- /dev/null
+++ b/drivers/gpu/drm/imagination/pvr_check.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/* Copyright (c) 2026 Imagination Technologies Ltd. */
+
+#ifndef PVR_CHECK_H
+#define PVR_CHECK_H
+
+#include <linux/build_bug.h>
+#include <linux/overflow.h>
+#include <linux/stddef.h>
+
+#define OFFSET_CHECK(type, member, offset) \
+ static_assert(offsetof(type, member) == (offset), \
+ "offsetof(" #type ", " #member ") incorrect")
+
+#define SIZE_CHECK(type, size) \
+ static_assert(sizeof(type) == (size), #type " is incorrect size")
+
+#define ALIGN_CHECK(type, align) \
+ static_assert(__alignof__(type) <= (align), #type " has incorrect alignment")
+
+/*
+ * Where the last member of a struct is a flexible array member, using
+ * SIZE_CHECK() is pointless. If the structure is not already padded to
+ * alignment without the flexible array member, sizeof() will not match the
+ * offset of the flexible array member and the "correct" sizeof() value is
+ * completely meaningless.
+ *
+ * In those instances, use FLEX_ARRAY_CHECK() instead to assert that the final
+ * field is a flexible array member and that it behaves as expected.
+ */
+#define FLEX_ARRAY_CHECK(type, member) \
+ static_assert(flex_array_size((type *)NULL, member, 1) == \
+ sizeof_field(type, member[0]), \
+ #type "->" #member " is incorrect size")
+
+#endif /* PVR_CHECK_H */
diff --git a/drivers/gpu/drm/imagination/pvr_rogue_fwif_check.h b/drivers/gpu/drm/imagination/pvr_rogue_fwif_check.h
index e72f4064af18..5048866359b9 100644
--- a/drivers/gpu/drm/imagination/pvr_rogue_fwif_check.h
+++ b/drivers/gpu/drm/imagination/pvr_rogue_fwif_check.h
@@ -4,31 +4,7 @@
#ifndef PVR_ROGUE_FWIF_CHECK_H
#define PVR_ROGUE_FWIF_CHECK_H

-#include <linux/build_bug.h>
-#include <linux/overflow.h>
-#include <linux/stddef.h>
-
-#define OFFSET_CHECK(type, member, offset) \
- static_assert(offsetof(type, member) == (offset), \
- "offsetof(" #type ", " #member ") incorrect")
-
-#define SIZE_CHECK(type, size) \
- static_assert(sizeof(type) == (size), #type " is incorrect size")
-
-/*
- * Where the last member of a struct is a flexible array member, using
- * SIZE_CHECK() is pointless. If the structure is not already padded to
- * alignment without the flexible array member, sizeof() will not match the
- * offset of the flexible array member and the "correct" sizeof() value is
- * completely meaningless.
- *
- * In those instances, use FLEX_ARRAY_CHECK() instead to assert that the final
- * field is a flexible array member and that it behaves as expected.
- */
-#define FLEX_ARRAY_CHECK(type, member) \
- static_assert(flex_array_size((type *)NULL, member, 1) == \
- sizeof_field(type, member[0]), \
- #type "->" #member " is incorrect size")
+#include "pvr_check.h"

OFFSET_CHECK(struct rogue_fwif_file_info_buf, path, 0);
OFFSET_CHECK(struct rogue_fwif_file_info_buf, info, 200);
diff --git a/drivers/gpu/drm/imagination/pvr_rogue_fwif_client_check.h b/drivers/gpu/drm/imagination/pvr_rogue_fwif_client_check.h
index 54aa4474163e..467d1d2073a1 100644
--- a/drivers/gpu/drm/imagination/pvr_rogue_fwif_client_check.h
+++ b/drivers/gpu/drm/imagination/pvr_rogue_fwif_client_check.h
@@ -4,14 +4,7 @@
#ifndef PVR_ROGUE_FWIF_CLIENT_CHECK_H
#define PVR_ROGUE_FWIF_CLIENT_CHECK_H

-#include <linux/build_bug.h>
-
-#define OFFSET_CHECK(type, member, offset) \
- static_assert(offsetof(type, member) == (offset), \
- "offsetof(" #type ", " #member ") incorrect")
-
-#define SIZE_CHECK(type, size) \
- static_assert(sizeof(type) == (size), #type " is incorrect size")
+#include "pvr_check.h"

OFFSET_CHECK(struct rogue_fwif_geom_regs, vdm_ctrl_stream_base, 0);
OFFSET_CHECK(struct rogue_fwif_geom_regs, tpu_border_colour_table, 8);
diff --git a/drivers/gpu/drm/imagination/pvr_rogue_fwif_shared_check.h b/drivers/gpu/drm/imagination/pvr_rogue_fwif_shared_check.h
index 597ed54bbd3a..59ef0a9aa395 100644
--- a/drivers/gpu/drm/imagination/pvr_rogue_fwif_shared_check.h
+++ b/drivers/gpu/drm/imagination/pvr_rogue_fwif_shared_check.h
@@ -4,14 +4,7 @@
#ifndef PVR_ROGUE_FWIF_SHARED_CHECK_H
#define PVR_ROGUE_FWIF_SHARED_CHECK_H

-#include <linux/build_bug.h>
-
-#define OFFSET_CHECK(type, member, offset) \
- static_assert(offsetof(type, member) == (offset), \
- "offsetof(" #type ", " #member ") incorrect")
-
-#define SIZE_CHECK(type, size) \
- static_assert(sizeof(type) == (size), #type " is incorrect size")
+#include "pvr_check.h"

OFFSET_CHECK(struct rogue_fwif_dma_addr, dev_addr, 0);
OFFSET_CHECK(struct rogue_fwif_dma_addr, fw_addr, 8);

--
2.43.0