Commit e50db383 authored by Paulo Miguel Almeida's avatar Paulo Miguel Almeida Committed by Alex Deucher

drm/amdgpu: Replace 1-element array with flexible-array member

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 structs _ATOM_GPIO_PIN_ASSIGNMENT,
_ATOM_DISPLAY_OBJECT_PATH, _ATOM_DISPLAY_OBJECT_PATH_TABLE,
_ATOM_OBJECT_TABLE and refactor the rest of the code accordingly.

Important to mention is that doing a build before/after this patch results
in no functional binary output differences.

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: default avatarPaulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 10276a20
...@@ -138,7 +138,9 @@ static uint8_t get_number_of_objects(struct bios_parser *bp, uint32_t offset) ...@@ -138,7 +138,9 @@ static uint8_t get_number_of_objects(struct bios_parser *bp, uint32_t offset)
uint32_t object_table_offset = bp->object_info_tbl_offset + offset; uint32_t object_table_offset = bp->object_info_tbl_offset + offset;
table = GET_IMAGE(ATOM_OBJECT_TABLE, object_table_offset); table = ((ATOM_OBJECT_TABLE *) bios_get_image(&bp->base,
object_table_offset,
struct_size(table, asObjects, 1)));
if (!table) if (!table)
return 0; return 0;
...@@ -166,8 +168,9 @@ static struct graphics_object_id bios_parser_get_connector_id( ...@@ -166,8 +168,9 @@ static struct graphics_object_id bios_parser_get_connector_id(
uint32_t connector_table_offset = bp->object_info_tbl_offset uint32_t connector_table_offset = bp->object_info_tbl_offset
+ le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset); + le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset);
ATOM_OBJECT_TABLE *tbl = ATOM_OBJECT_TABLE *tbl = ((ATOM_OBJECT_TABLE *) bios_get_image(&bp->base,
GET_IMAGE(ATOM_OBJECT_TABLE, connector_table_offset); connector_table_offset,
struct_size(tbl, asObjects, 1)));
if (!tbl) { if (!tbl) {
dm_error("Can't get connector table from atom bios.\n"); dm_error("Can't get connector table from atom bios.\n");
...@@ -1789,11 +1792,13 @@ static enum bp_result bios_parser_get_gpio_pin_info( ...@@ -1789,11 +1792,13 @@ static enum bp_result bios_parser_get_gpio_pin_info(
if (!DATA_TABLES(GPIO_Pin_LUT)) if (!DATA_TABLES(GPIO_Pin_LUT))
return BP_RESULT_BADBIOSTABLE; return BP_RESULT_BADBIOSTABLE;
header = GET_IMAGE(ATOM_GPIO_PIN_LUT, DATA_TABLES(GPIO_Pin_LUT)); header = ((ATOM_GPIO_PIN_LUT *) bios_get_image(&bp->base,
DATA_TABLES(GPIO_Pin_LUT),
struct_size(header, asGPIO_Pin, 1)));
if (!header) if (!header)
return BP_RESULT_BADBIOSTABLE; return BP_RESULT_BADBIOSTABLE;
if (sizeof(ATOM_COMMON_TABLE_HEADER) + sizeof(ATOM_GPIO_PIN_LUT) if (sizeof(ATOM_COMMON_TABLE_HEADER) + struct_size(header, asGPIO_Pin, 1)
> le16_to_cpu(header->sHeader.usStructureSize)) > le16_to_cpu(header->sHeader.usStructureSize))
return BP_RESULT_BADBIOSTABLE; return BP_RESULT_BADBIOSTABLE;
...@@ -1978,7 +1983,8 @@ static ATOM_OBJECT *get_bios_object(struct bios_parser *bp, ...@@ -1978,7 +1983,8 @@ static ATOM_OBJECT *get_bios_object(struct bios_parser *bp,
offset += bp->object_info_tbl_offset; offset += bp->object_info_tbl_offset;
tbl = GET_IMAGE(ATOM_OBJECT_TABLE, offset); tbl = ((ATOM_OBJECT_TABLE *) bios_get_image(&bp->base, offset,
struct_size(tbl, asObjects, 1)));
if (!tbl) if (!tbl)
return NULL; return NULL;
...@@ -2709,8 +2715,9 @@ static enum bp_result get_bracket_layout_record( ...@@ -2709,8 +2715,9 @@ static enum bp_result get_bracket_layout_record(
genericTableOffset = bp->object_info_tbl_offset + genericTableOffset = bp->object_info_tbl_offset +
bp->object_info_tbl.v1_3->usMiscObjectTableOffset; bp->object_info_tbl.v1_3->usMiscObjectTableOffset;
object_table = (ATOM_OBJECT_TABLE *) object_table = ((ATOM_OBJECT_TABLE *) bios_get_image(&bp->base,
GET_IMAGE(ATOM_OBJECT_TABLE, genericTableOffset); genericTableOffset,
struct_size(object_table, asObjects, 1)));
if (!object_table) if (!object_table)
return BP_RESULT_FAILURE; return BP_RESULT_FAILURE;
......
...@@ -4386,7 +4386,7 @@ typedef struct _ATOM_GPIO_PIN_ASSIGNMENT ...@@ -4386,7 +4386,7 @@ typedef struct _ATOM_GPIO_PIN_ASSIGNMENT
typedef struct _ATOM_GPIO_PIN_LUT typedef struct _ATOM_GPIO_PIN_LUT
{ {
ATOM_COMMON_TABLE_HEADER sHeader; ATOM_COMMON_TABLE_HEADER sHeader;
ATOM_GPIO_PIN_ASSIGNMENT asGPIO_Pin[1]; ATOM_GPIO_PIN_ASSIGNMENT asGPIO_Pin[];
}ATOM_GPIO_PIN_LUT; }ATOM_GPIO_PIN_LUT;
/****************************************************************************/ /****************************************************************************/
...@@ -4513,7 +4513,7 @@ typedef struct _ATOM_DISPLAY_OBJECT_PATH ...@@ -4513,7 +4513,7 @@ typedef struct _ATOM_DISPLAY_OBJECT_PATH
USHORT usSize; //the size of ATOM_DISPLAY_OBJECT_PATH USHORT usSize; //the size of ATOM_DISPLAY_OBJECT_PATH
USHORT usConnObjectId; //Connector Object ID USHORT usConnObjectId; //Connector Object ID
USHORT usGPUObjectId; //GPU ID USHORT usGPUObjectId; //GPU ID
USHORT usGraphicObjIds[1]; //1st Encoder Obj source from GPU to last Graphic Obj destinate to connector. USHORT usGraphicObjIds[]; //1st Encoder Obj source from GPU to last Graphic Obj destinate to connector.
}ATOM_DISPLAY_OBJECT_PATH; }ATOM_DISPLAY_OBJECT_PATH;
typedef struct _ATOM_DISPLAY_EXTERNAL_OBJECT_PATH typedef struct _ATOM_DISPLAY_EXTERNAL_OBJECT_PATH
...@@ -4530,7 +4530,7 @@ typedef struct _ATOM_DISPLAY_OBJECT_PATH_TABLE ...@@ -4530,7 +4530,7 @@ typedef struct _ATOM_DISPLAY_OBJECT_PATH_TABLE
UCHAR ucNumOfDispPath; UCHAR ucNumOfDispPath;
UCHAR ucVersion; UCHAR ucVersion;
UCHAR ucPadding[2]; UCHAR ucPadding[2];
ATOM_DISPLAY_OBJECT_PATH asDispPath[1]; ATOM_DISPLAY_OBJECT_PATH asDispPath[];
}ATOM_DISPLAY_OBJECT_PATH_TABLE; }ATOM_DISPLAY_OBJECT_PATH_TABLE;
typedef struct _ATOM_OBJECT //each object has this structure typedef struct _ATOM_OBJECT //each object has this structure
...@@ -4545,7 +4545,7 @@ typedef struct _ATOM_OBJECT_TABLE //Above 4 object table ...@@ -4545,7 +4545,7 @@ typedef struct _ATOM_OBJECT_TABLE //Above 4 object table
{ {
UCHAR ucNumberOfObjects; UCHAR ucNumberOfObjects;
UCHAR ucPadding[3]; UCHAR ucPadding[3];
ATOM_OBJECT asObjects[1]; ATOM_OBJECT asObjects[];
}ATOM_OBJECT_TABLE; }ATOM_OBJECT_TABLE;
typedef struct _ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT //usSrcDstTableOffset pointing to this structure typedef struct _ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT //usSrcDstTableOffset pointing to this structure
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment