Skip to content

Commit 77f183d

Browse files
GustavoARSilvaDanilo Krummrich
authored andcommitted
drm/nouveau: Avoid multiple -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. So, in order to avoid ending up with flexible-array members in the middle of other structs, we use the `struct_group_tagged()` helper to separate the flexible arrays from the rest of the members in the flexible structures. We then use the newly created tagged `struct nvif_ioctl_v0_hdr` and `struct nvif_ioctl_mthd_v0_hdr` to replace the type of the objects causing trouble in multiple structures. We also want to ensure that when new members need to be added to the flexible structures, they are always included within the newly created tagged structs. For this, we use `static_assert()`. This ensures that the memory layout for both the flexible structure and the new tagged struct is the same after any changes. So, with these changes, fix the following warnings: drivers/gpu/drm/nouveau/nvif/object.c:60:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/gpu/drm/nouveau/nvif/object.c:233:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/gpu/drm/nouveau/nvif/object.c:214:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/gpu/drm/nouveau/nvif/object.c:152:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/gpu/drm/nouveau/nvif/object.c:138:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/gpu/drm/nouveau/nvif/object.c:104:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/gpu/drm/nouveau/nouveau_svm.c:83:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/gpu/drm/nouveau/nouveau_svm.c:82:30: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Signed-off-by: Gustavo A. R. Silva <[email protected]> Acked-by: Dave Airlie <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/Z6xjZhHxRp4Bu_SX@kspp
1 parent cd740b8 commit 77f183d

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

drivers/gpu/drm/nouveau/include/nvif/ioctl.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@
33
#define __NVIF_IOCTL_H__
44

55
struct nvif_ioctl_v0 {
6-
__u8 version;
6+
/* New members MUST be added within the struct_group() macro below. */
7+
struct_group_tagged(nvif_ioctl_v0_hdr, __hdr,
8+
__u8 version;
79
#define NVIF_IOCTL_V0_SCLASS 0x01
810
#define NVIF_IOCTL_V0_NEW 0x02
911
#define NVIF_IOCTL_V0_DEL 0x03
1012
#define NVIF_IOCTL_V0_MTHD 0x04
1113
#define NVIF_IOCTL_V0_MAP 0x07
1214
#define NVIF_IOCTL_V0_UNMAP 0x08
13-
__u8 type;
14-
__u8 pad02[4];
15+
__u8 type;
16+
__u8 pad02[4];
1517
#define NVIF_IOCTL_V0_OWNER_NVIF 0x00
1618
#define NVIF_IOCTL_V0_OWNER_ANY 0xff
17-
__u8 owner;
19+
__u8 owner;
1820
#define NVIF_IOCTL_V0_ROUTE_NVIF 0x00
1921
#define NVIF_IOCTL_V0_ROUTE_HIDDEN 0xff
20-
__u8 route;
21-
__u64 token;
22-
__u64 object;
22+
__u8 route;
23+
__u64 token;
24+
__u64 object;
25+
);
2326
__u8 data[]; /* ioctl data (below) */
2427
};
28+
static_assert(offsetof(struct nvif_ioctl_v0, data) == sizeof(struct nvif_ioctl_v0_hdr),
29+
"struct member likely outside of struct_group()");
2530

2631
struct nvif_ioctl_sclass_v0 {
2732
/* nvif_ioctl ... */
@@ -51,12 +56,17 @@ struct nvif_ioctl_del {
5156
};
5257

5358
struct nvif_ioctl_mthd_v0 {
54-
/* nvif_ioctl ... */
55-
__u8 version;
56-
__u8 method;
57-
__u8 pad02[6];
59+
/* New members MUST be added within the struct_group() macro below. */
60+
struct_group_tagged(nvif_ioctl_mthd_v0_hdr, __hdr,
61+
/* nvif_ioctl ... */
62+
__u8 version;
63+
__u8 method;
64+
__u8 pad02[6];
65+
);
5866
__u8 data[]; /* method data (class.h) */
5967
};
68+
static_assert(offsetof(struct nvif_ioctl_mthd_v0, data) == sizeof(struct nvif_ioctl_mthd_v0_hdr),
69+
"struct member likely outside of struct_group()");
6070

6171
struct nvif_ioctl_map_v0 {
6272
/* nvif_ioctl ... */

drivers/gpu/drm/nouveau/nouveau_svm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ struct nouveau_svm {
7979
#define SVM_ERR(s,f,a...) NV_WARN((s)->drm, "svm: "f"\n", ##a)
8080

8181
struct nouveau_pfnmap_args {
82-
struct nvif_ioctl_v0 i;
83-
struct nvif_ioctl_mthd_v0 m;
82+
struct nvif_ioctl_v0_hdr i;
83+
struct nvif_ioctl_mthd_v0_hdr m;
8484
struct nvif_vmm_pfnmap_v0 p;
8585
};
8686

drivers/gpu/drm/nouveau/nvif/object.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int
5757
nvif_object_sclass_get(struct nvif_object *object, struct nvif_sclass **psclass)
5858
{
5959
struct {
60-
struct nvif_ioctl_v0 ioctl;
60+
struct nvif_ioctl_v0_hdr ioctl;
6161
struct nvif_ioctl_sclass_v0 sclass;
6262
} *args = NULL;
6363
int ret, cnt = 0, i;
@@ -101,7 +101,7 @@ int
101101
nvif_object_mthd(struct nvif_object *object, u32 mthd, void *data, u32 size)
102102
{
103103
struct {
104-
struct nvif_ioctl_v0 ioctl;
104+
struct nvif_ioctl_v0_hdr ioctl;
105105
struct nvif_ioctl_mthd_v0 mthd;
106106
} *args;
107107
u32 args_size;
@@ -135,7 +135,7 @@ void
135135
nvif_object_unmap_handle(struct nvif_object *object)
136136
{
137137
struct {
138-
struct nvif_ioctl_v0 ioctl;
138+
struct nvif_ioctl_v0_hdr ioctl;
139139
struct nvif_ioctl_unmap unmap;
140140
} args = {
141141
.ioctl.type = NVIF_IOCTL_V0_UNMAP,
@@ -149,7 +149,7 @@ nvif_object_map_handle(struct nvif_object *object, void *argv, u32 argc,
149149
u64 *handle, u64 *length)
150150
{
151151
struct {
152-
struct nvif_ioctl_v0 ioctl;
152+
struct nvif_ioctl_v0_hdr ioctl;
153153
struct nvif_ioctl_map_v0 map;
154154
} *args;
155155
u32 argn = sizeof(*args) + argc;
@@ -211,7 +211,7 @@ void
211211
nvif_object_dtor(struct nvif_object *object)
212212
{
213213
struct {
214-
struct nvif_ioctl_v0 ioctl;
214+
struct nvif_ioctl_v0_hdr ioctl;
215215
struct nvif_ioctl_del del;
216216
} args = {
217217
.ioctl.type = NVIF_IOCTL_V0_DEL,
@@ -230,7 +230,7 @@ nvif_object_ctor(struct nvif_object *parent, const char *name, u32 handle,
230230
s32 oclass, void *data, u32 size, struct nvif_object *object)
231231
{
232232
struct {
233-
struct nvif_ioctl_v0 ioctl;
233+
struct nvif_ioctl_v0_hdr ioctl;
234234
struct nvif_ioctl_new_v0 new;
235235
} *args;
236236
int ret = 0;

0 commit comments

Comments
 (0)