All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [next] drm/amdgpu: Replace one-element array with flexible-array member
@ 2022-10-28  5:10 Paulo Miguel Almeida
  2022-10-28  7:18 ` Christian König
  0 siblings, 1 reply; 16+ messages in thread
From: Paulo Miguel Almeida @ 2022-10-28  5:10 UTC (permalink / raw)
  To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
	Daniel Vetter, Hans de Goede, Grigory Vasilyev,
	Paulo Miguel Almeida, Claudio Suarez, Slark Xiao, Rongguang Wei,
	amd-gfx, dri-devel
  Cc: linux-kernel, linux-hardening

One-element arrays are deprecated, and we are replacing them with
flexible array members instead. So, replace one-element array with
flexible-array member in struct _ATOM_FAKE_EDID_PATCH_RECORD and
refactor the rest of the code accordingly.

This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -fstrict-flex-arrays=3 [1].

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/238
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1]

Signed-off-by: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/atombios_encoders.c | 10 +++++++---
 drivers/gpu/drm/amd/include/atombios.h         |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
index 6be9ac2b9c5b..6b5abf1249db 100644
--- a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
+++ b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
@@ -2079,10 +2079,14 @@ amdgpu_atombios_encoder_get_lcd_info(struct amdgpu_encoder *encoder)
 							} else
 								kfree(edid);
 						}
+
+						record += struct_size(fake_edid_record,
+								      ucFakeEDIDString,
+								      fake_edid_record->ucFakeEDIDLength);
+					} else {
+						/* empty fake edid record must be 3 bytes long */
+						record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD) + 1;
 					}
-					record += fake_edid_record->ucFakeEDIDLength ?
-						fake_edid_record->ucFakeEDIDLength + 2 :
-						sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
 					break;
 				case LCD_PANEL_RESOLUTION_RECORD_TYPE:
 					panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
diff --git a/drivers/gpu/drm/amd/include/atombios.h b/drivers/gpu/drm/amd/include/atombios.h
index 15943bc21bc5..b5b1d073f8e2 100644
--- a/drivers/gpu/drm/amd/include/atombios.h
+++ b/drivers/gpu/drm/amd/include/atombios.h
@@ -4107,7 +4107,7 @@ typedef struct _ATOM_FAKE_EDID_PATCH_RECORD
 {
   UCHAR ucRecordType;
   UCHAR ucFakeEDIDLength;       // = 128 means EDID length is 128 bytes, otherwise the EDID length = ucFakeEDIDLength*128
-  UCHAR ucFakeEDIDString[1];    // This actually has ucFakeEdidLength elements.
+  UCHAR ucFakeEDIDString[];     // This actually has ucFakeEdidLength elements.
 } ATOM_FAKE_EDID_PATCH_RECORD;
 
 typedef struct  _ATOM_PANEL_RESOLUTION_PATCH_RECORD
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-11-02 16:17 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-28  5:10 [PATCH] [next] drm/amdgpu: Replace one-element array with flexible-array member Paulo Miguel Almeida
2022-10-28  7:18 ` Christian König
2022-10-28 16:36   ` Kees Cook
2022-10-28 16:36     ` Kees Cook
2022-10-28 16:36     ` Kees Cook
2022-10-28 17:33     ` Christian König
2022-10-28 17:33       ` Christian König
2022-10-28 17:33       ` Christian König
2022-10-29  0:43       ` Paulo Miguel Almeida
2022-10-29  0:43         ` Paulo Miguel Almeida
2022-10-29  0:43         ` Paulo Miguel Almeida
2022-10-29  1:30         ` [PATCH v2] " Paulo Miguel Almeida
2022-10-29  1:30           ` Paulo Miguel Almeida
2022-11-02 16:12           ` Alex Deucher
2022-11-02 16:12             ` Alex Deucher
2022-11-02 16:12             ` Alex Deucher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.