drm/nouveau: Avoid -Wflex-array-member-not-at-end warning
Subsystems (3)
PATCH 1/1 drm/nouveau: Avoid -Wflex-array-member-not-at-end warning
Use the DEFINE_RAW_FLEX() helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly.
So, with this, fix the following warning:
drivers/gpu/drm/nouveau/dispnv50/disp.c:779:47: 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/dispnv50/disp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/disp.c +9 -11
@@ -774,11 +774,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi;union hdmi_infoframe infoframe = {0 };const u8 rekey =56 ;/* binary driver, and tegra, constant */ + DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, 17); +const u8 data_len =17 ;/* same length as in DEFINE_RAW_FLEX above. */ u32 max_ac_packet; -struct { -struct nvif_outp_infoframe_v0 infoframe; -u8 data[17 ]; - } args = {0 };int ret, size; max_ac_packet = mode->htotal - mode->hdisplay;
@@ -815,29 +813,29 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,return ;/* AVI InfoFrame. */ - args.infoframe.version =0 ; - args.infoframe.head = nv_crtc->index; + args->version =0 ; + args->head = nv_crtc->index;if (!drm_hdmi_avi_infoframe_from_display_mode (&infoframe.avi, &nv_connector->base, mode)) {drm_hdmi_avi_infoframe_quant_range (&infoframe.avi, &nv_connector->base, mode,HDMI_QUANTIZATION_RANGE_FULL ); - size =hdmi_infoframe_pack (&infoframe, args.data,ARRAY_SIZE (args.data)); + size =hdmi_infoframe_pack (&infoframe, args->data, data_len); }else { size =0 ; } -nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_AVI , &args.infoframe, size); +nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_AVI , args, size);/* Vendor InfoFrame. */ -memset (&args.data,0 ,sizeof (args.data)); +memset (args->data,0 , data_len);if (!drm_hdmi_vendor_infoframe_from_display_mode (&infoframe.vendor.hdmi, &nv_connector->base, mode)) - size =hdmi_infoframe_pack (&infoframe, args.data,ARRAY_SIZE (args.data)); + size =hdmi_infoframe_pack (&infoframe, args->data, data_len);else size =0 ; -nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_VSI , &args.infoframe, size); +nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_VSI , args, size); nv_encoder->hdmi.enabled = true; }
Signature · 1 line
2.34.1
Quoted 19 lines · Gustavo A. R. Silva
Use the
DEFINE_RAW_FLEX()helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly.So, with this, fix the following warning:
drivers/gpu/drm/nouveau/dispnv50/disp.c:779:47: 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]>--- drivers/gpu/drm/nouveau/dispnv50/disp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/gpu/drm/nouveau/dispnv50/disp.c +0
-0
drivers/gpu/drm/nouveau/dispnv50/disp.c nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc, · line 778
Quoted 5 lines
drivers/gpu/drm/nouveau/dispnv50/disp.c +2
-0@@ -774,11 +774,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi;union hdmi_infoframe infoframe = {0 };const u8 rekey =56 ;/* binary driver, and tegra, constant */ + DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, 17); +const u8 data_len =17 ;/* same length as in DEFINE_RAW_FLEX above. */
To avoid repeating the open-coded "17", this could either be a define:
nv50_hdmi_enable(...)
{
...
#define data_len 17 DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, data_len);
...rest of function...
#undef data_len
}
or an ungainly but compile-time calculated value that exposes some DEFINE_FLEX internals:
const u8 data_len = (sizeof(args_u) - sizeof(*args)) / sizeof(*args->data);
(Maybe a helper is needed for that?)
#define STACK_FLEX_COUNT(name, member) \ ((sizeof(name##_u) = sizeof(*(name))) / sizeof(*(name)->member))
drivers/gpu/drm/nouveau/dispnv50/disp.c nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc, · line 817
Quoted 8 lines
drivers/gpu/drm/nouveau/dispnv50/disp.c +2
-2@@ -815,29 +813,29 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,return ;/* AVI InfoFrame. */ - args.infoframe.version =0 ; - args.infoframe.head = nv_crtc->index; + args->version =0 ; + args->head = nv_crtc->index;
The stack variable (was before and is again) already zero-initialized, so the "= 0" line shouldn't be needed.
But neither of these comments are show-stoppers, IMO.
Signature · 1 line
Kees Cook
Quoted 33 lines · Kees Cook
Quoted 19 lines · Gustavo A. R. Silva
Use the
DEFINE_RAW_FLEX()helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly.So, with this, fix the following warning:
drivers/gpu/drm/nouveau/dispnv50/disp.c:779:47: 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]>--- drivers/gpu/drm/nouveau/dispnv50/disp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/gpu/drm/nouveau/dispnv50/disp.c +0
-0drivers/gpu/drm/nouveau/dispnv50/disp.c nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc, · line 778
Quoted 5 lines
drivers/gpu/drm/nouveau/dispnv50/disp.c +2
-0@@ -774,11 +774,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi;union hdmi_infoframe infoframe = {0 };const u8 rekey =56 ;/* binary driver, and tegra, constant */ + DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, 17); +const u8 data_len =17 ;/* same length as in DEFINE_RAW_FLEX above. */ To avoid repeating the open-coded "17", this could either be a define:
nv50_hdmi_enable(...)
{
...#define data_len 17 DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, data_len);
Quoted 8 lines
...rest of function...
#undefdata_len
}or an ungainly but compile-time calculated value that exposes some
DEFINE_FLEXinternals:const u8 data_len = (sizeof(args_u) - sizeof(*args)) / sizeof(*args->data);
Yeah, I actually thought of something more like just __struct_size(args) - sizeof(*args), as the flex array member is __u8 data[].
Quoted 5 lines
(Maybe a helper is needed for that?)
#define STACK_FLEX_COUNT(name, member) \ ((sizeof(name##_u) = sizeof(*(name))) / sizeof(*(name)->member))
I don't like this sizeof(name##_u) part as it is detached from the DEFINE_RAW_FLEX() internals. Probably use __struct_size(args) instead, as in the example above.
Quoted 13 lines
drivers/gpu/drm/nouveau/dispnv50/disp.c nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc, · line 817
Quoted 9 lines
drivers/gpu/drm/nouveau/dispnv50/disp.c +2
-2@@ -815,29 +813,29 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,return ;/* AVI InfoFrame. */ - args.infoframe.version =0 ; - args.infoframe.head = nv_crtc->index; + args->version =0 ; + args->head = nv_crtc->index;The stack variable (was before and is again) already zero-initialized, so the "= 0" line shouldn't be needed.
Quoted 4 lines
But neither of these comments are show-stoppers, IMO.
Reviewed-by Kees Cook <[email protected]>
Thanks!
--
Gustavo
Hi all,
Friendly ping: who can take this, please? 🙂
Thanks
-Gustavo
Quoted 69 lines · Gustavo A. R. Silva
Use the
DEFINE_RAW_FLEX()helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly.So, with this, fix the following warning:
drivers/gpu/drm/nouveau/dispnv50/disp.c:779:47: 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]>--- drivers/gpu/drm/nouveau/dispnv50/disp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/gpu/drm/nouveau/dispnv50/disp.c +9
-11@@ -774,11 +774,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi;union hdmi_infoframe infoframe = {0 };const u8 rekey =56 ;/* binary driver, and tegra, constant */ + DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, 17); +const u8 data_len =17 ;/* same length as in DEFINE_RAW_FLEX above. */ u32 max_ac_packet; -struct { -struct nvif_outp_infoframe_v0 infoframe; -u8 data[17 ]; - } args = {0 };int ret, size; max_ac_packet = mode->htotal - mode->hdisplay;@@ -815,29 +813,29 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,return ;/* AVI InfoFrame. */ - args.infoframe.version =0 ; - args.infoframe.head = nv_crtc->index; + args->version =0 ; + args->head = nv_crtc->index;if (!drm_hdmi_avi_infoframe_from_display_mode (&infoframe.avi, &nv_connector->base, mode)) {drm_hdmi_avi_infoframe_quant_range (&infoframe.avi, &nv_connector->base, mode,HDMI_QUANTIZATION_RANGE_FULL ); - size =hdmi_infoframe_pack (&infoframe, args.data,ARRAY_SIZE (args.data)); + size =hdmi_infoframe_pack (&infoframe, args->data, data_len); }else { size =0 ; } -nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_AVI , &args.infoframe, size); +nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_AVI , args, size);/* Vendor InfoFrame. */ -memset (&args.data,0 ,sizeof (args.data)); +memset (args->data,0 , data_len);if (!drm_hdmi_vendor_infoframe_from_display_mode (&infoframe.vendor.hdmi, &nv_connector->base, mode)) - size =hdmi_infoframe_pack (&infoframe, args.data,ARRAY_SIZE (args.data)); + size =hdmi_infoframe_pack (&infoframe, args->data, data_len);else size =0 ; -nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_VSI , &args.infoframe, size); +nvif_outp_infoframe (&nv_encoder->outp,NVIF_OUTP_INFOFRAME_V0_VSI , args, size); nv_encoder->hdmi.enabled = true; }
Danilo Krummrich
maintainerHi,
Quoted 3 lines · Gustavo A. R. Silva
Hi all,
Friendly ping: who can take this, please? 🙂
Usually, that's me. But I thought you might want to send a v2 based on Kees' comments?
- Danilo
Quoted 75 lines
Thanks
-GustavoQuoted 69 lines · Gustavo A. R. Silva
Use the
DEFINE_RAW_FLEX()helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly.So, with this, fix the following warning:
drivers/gpu/drm/nouveau/dispnv50/disp.c:779:47: 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]>---
drivers/gpu/drm/nouveau/dispnv50/disp.c| 20 +++++++++-----------1 file changed, 9 insertions(+), 11 deletions(-)drivers/gpu/drm/nouveau/dispnv50/disp.c +0
-0@@ -774,11 +774,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc, struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi; union hdmi_infoframe infoframe = { 0 };const u8 rekey = 56; /* binary driver, and tegra, constant */ +
DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, 17); + const u8data_len= 17; /* same length as inDEFINE_RAW_FLEXabove. */ u32max_ac_packet;
- struct {
- structnvif_outp_infoframe_v0infoframe;
- u8 data[17];
- } args = { 0 };
int ret, size;
max_ac_packet =mode->htotal-mode->hdisplay;drivers/gpu/drm/nouveau/dispnv50/disp.c +6
-6@@ -815,29 +813,29 @@ nv50_hdmi_enable(struct drm_encoder *encoder, structnouveau_crtc *nv_crtc, return; /* AVI InfoFrame. */ - args.infoframe.version = 0; - args.infoframe.head = nv_crtc->index; + args->version = 0; + args->head = nv_crtc->index; if (!drm_hdmi_avi_infoframe_from_display_mode(&infoframe.avi, &nv_connector->base, mode)) { drm_hdmi_avi_infoframe_quant_range(&infoframe.avi, &nv_connector->base, mode, HDMI_QUANTIZATION_RANGE_FULL); - size = hdmi_infoframe_pack(&infoframe, args.data, ARRAY_SIZE(args.data)); + size = hdmi_infoframe_pack(&infoframe, args->data, data_len); } else { size = 0; } - nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_AVI, &args.infoframe, size); + nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_AVI, args, size); /* Vendor InfoFrame. */ - memset(&args.data, 0, sizeof(args.data)); + memset(args->data, 0, data_len); if (!drm_hdmi_vendor_infoframe_from_display_mode(&infoframe.vendor.hdmi, &nv_connector->base, mode)) - size = hdmi_infoframe_pack(&infoframe, args.data, ARRAY_SIZE(args.data)); + size = hdmi_infoframe_pack(&infoframe, args->data, data_len);else
size = 0;
-nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_VSI, &args.infoframe, size);
+nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_VSI, args, size);
nv_encoder->hdmi.enabled= true;
}
Danilo Krummrich
maintainerQuoted 9 lines · Danilo Krummrich
Hi,
Quoted 3 lines · Gustavo A. R. Silva
Hi all,
Friendly ping: who can take this, please? 🙂
Usually, that's me. But I thought you might want to send a v2 based on Kees' comments?
Do you plan to follow up on this? I'd prefer if we could get rid of the open- coded "17". So, maybe just go with the define until we have something like STACK_FLEX_COUNT()?
Quoted 79 lines
- Danilo
Quoted 76 lines
Thanks
-GustavoQuoted 70 lines · Gustavo A. R. Silva
Use the
DEFINE_RAW_FLEX()helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly.So, with this, fix the following warning:
drivers/gpu/drm/nouveau/dispnv50/disp.c:779:47: 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]>---
drivers/gpu/drm/nouveau/dispnv50/disp.c| 20 +++++++++-----------1 file changed, 9 insertions(+), 11 deletions(-)drivers/gpu/drm/nouveau/dispnv50/disp.c +0
-0@@ -774,11 +774,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc, struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi; union hdmi_infoframe infoframe = { 0 };const u8 rekey = 56; /* binary driver, and tegra, constant */ +
DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, 17); + const u8data_len= 17; /* same length as inDEFINE_RAW_FLEXabove. */ u32max_ac_packet;
- struct {
- structnvif_outp_infoframe_v0infoframe;
- u8 data[17];
- } args = { 0 };
int ret, size;
max_ac_packet =mode->htotal-mode->hdisplay;drivers/gpu/drm/nouveau/dispnv50/disp.c +2
-2@@ -815,29 +813,29 @@ nv50_hdmi_enable(struct drm_encoder *encoder, structnouveau_crtc *nv_crtc, return; /* AVI InfoFrame. */ - args.infoframe.version = 0; - args.infoframe.head = nv_crtc->index; + args->version = 0; + args->head = nv_crtc->index; if (!drm_hdmi_avi_infoframe_from_display_mode(&infoframe.avi, &nv_connector->base, mode)) {drm_hdmi_avi_infoframe_quant_range(&infoframe.avi, &nv_connector-
Quoted 1 line
base, mode,
HDMI_QUANTIZATION_RANGE_FULL);
- size =hdmi_infoframe_pack(&infoframe, args.data, ARRAY_SIZE(args.data));
+ size =hdmi_infoframe_pack(&infoframe, args->data, data_len); } else {
size = 0;
}
-nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_AVI, &args.infoframe, size);
+nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_AVI, args, size);
/* Vendor InfoFrame. */
-memset(&args.data, 0, sizeof(args.data));
+memset(args->data, 0, data_len);
if (!drm_hdmi_vendor_infoframe_from_display_mode(&infoframe.vendor.hdmi,&nv_connector->base, mode))
- size =hdmi_infoframe_pack(&infoframe, args.data, ARRAY_SIZE(args.data));
+ size =hdmi_infoframe_pack(&infoframe, args->data, data_len); else
size = 0;
-nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_VSI, &args.infoframe, size);
+nvif_outp_infoframe(&nv_encoder->outp, NVIF_OUTP_INFOFRAME_V0_VSI, args, size);
nv_encoder->hdmi.enabled= true;
}
Quoted 6 lines · Danilo Krummrich
Quoted 5 lines · Danilo Krummrich
Hi,
Quoted 2 lines · Gustavo A. R. Silva
Hi all,
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Friendly ping: who can take this, please? 🙂
Usually, that's me. But I thought you might want to send a v2 based on Kees' comments?
Do you plan to follow up on this? I'd prefer if we could get rid of the open- coded "17". So, maybe just go with the define until we have something like
STACK_FLEX_COUNT()?
Do you mean the following define...?
nv50_hdmi_enable(...)
{
...
#define data_len 17
DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, data_len);...rest of function...
#undef data_len
}
Thanks
--
Gustavo
Danilo Krummrich
maintainerQuoted 18 lines · Gustavo A. R. Silva
Quoted 6 lines · Danilo Krummrich
Quoted 5 lines · Danilo Krummrich
Hi,
Quoted 2 lines · Gustavo A. R. Silva
Hi all,
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Friendly ping: who can take this, please? 🙂
Usually, that's me. But I thought you might want to send a v2 based on Kees' comments?
Do you plan to follow up on this? I'd prefer if we could get rid of the open- coded "17". So, maybe just go with the define until we have something like
STACK_FLEX_COUNT()?
Quoted 9 lines
Do you mean the following define...?>
nv50_hdmi_enable(...)
{
...
#define data_len 17
DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, data_len);
...rest of function...
#undefdata_len
}
Yes, it's not great, but I think it's better than having the length in two places.
Quoted 5 lines
Thanks
Signature · 1 line
Gustavo
Quoted 4 lines
Yes, it's not great, but I think it's better than having the length in two places.
Agreed. I'll respin. :)
Thanks
--
Gustavo
Quoted 5 lines · Danilo Krummrich
Quoted 1 line · Danilo Krummrich
I am reminded that I should check all my MUAs to render the date as YYYY-MM-DD so my brain doesn't explode when I see people "time traveling". ;)
(BTW, what MUAs do you both use? I use Mutt and K-9 Mail, and I need to check the quote prefix settings in both...)
-Kees
Signature · 1 line
Kees Cook
Danilo Krummrich
maintainerQuoted 9 lines · Kees Cook
Quoted 5 lines · Danilo Krummrich
Quoted 1 line · Danilo Krummrich
I am reminded that I should check all my MUAs to render the date as YYYY-MM-DD so my brain doesn't explode when I see people "time traveling". ;)
(BTW, what MUAs do you both use? I use Mutt and K-9 Mail, and I need to check the quote prefix settings in both...)
Mutt, and (unfortunately) Thunderbird for HTML stuff and a few other rare cases.
Quoted 6 lines
-Kees
Signature · 1 line
Kees Cook