Skip to content

Commit 781d41f

Browse files
committed
drm/radeon: silence UBSAN warning (v3)
Convert a variable sized array from [1] to []. v2: fix up a few more. v3: integrate comments from Kees. Reviewed-by: Kees Cook <[email protected]> Tested-by: Jeff Johnson <[email protected]> (v2) Acked-by: Christian König <[email protected]> (v1) Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected]
1 parent 0ba753b commit 781d41f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/gpu/drm/radeon/pptable.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,22 +424,22 @@ typedef struct _ATOM_PPLIB_SUMO_CLOCK_INFO{
424424
typedef struct _ATOM_PPLIB_STATE_V2
425425
{
426426
//number of valid dpm levels in this state; Driver uses it to calculate the whole
427-
//size of the state: sizeof(ATOM_PPLIB_STATE_V2) + (ucNumDPMLevels - 1) * sizeof(UCHAR)
427+
//size of the state: struct_size(ATOM_PPLIB_STATE_V2, clockInfoIndex, ucNumDPMLevels)
428428
UCHAR ucNumDPMLevels;
429429

430430
//a index to the array of nonClockInfos
431431
UCHAR nonClockInfoIndex;
432432
/**
433433
* Driver will read the first ucNumDPMLevels in this array
434434
*/
435-
UCHAR clockInfoIndex[1];
435+
UCHAR clockInfoIndex[] __counted_by(ucNumDPMLevels);
436436
} ATOM_PPLIB_STATE_V2;
437437

438438
typedef struct _StateArray{
439439
//how many states we have
440440
UCHAR ucNumEntries;
441441

442-
ATOM_PPLIB_STATE_V2 states[1];
442+
ATOM_PPLIB_STATE_V2 states[] __counted_by(ucNumEntries);
443443
}StateArray;
444444

445445

@@ -450,7 +450,7 @@ typedef struct _ClockInfoArray{
450450
//sizeof(ATOM_PPLIB_CLOCK_INFO)
451451
UCHAR ucEntrySize;
452452

453-
UCHAR clockInfo[1];
453+
UCHAR clockInfo[] __counted_by(ucNumEntries);
454454
}ClockInfoArray;
455455

456456
typedef struct _NonClockInfoArray{
@@ -460,7 +460,7 @@ typedef struct _NonClockInfoArray{
460460
//sizeof(ATOM_PPLIB_NONCLOCK_INFO)
461461
UCHAR ucEntrySize;
462462

463-
ATOM_PPLIB_NONCLOCK_INFO nonClockInfo[1];
463+
ATOM_PPLIB_NONCLOCK_INFO nonClockInfo[] __counted_by(ucNumEntries);
464464
}NonClockInfoArray;
465465

466466
typedef struct _ATOM_PPLIB_Clock_Voltage_Dependency_Record

0 commit comments

Comments
 (0)