amd: use a valid size for ac_pm4_state allocation

If max_dw is smaller than the pm4 array the allocation size would be
smaller than sizeof(ac_pm4_state).

Fixes: 428601095c ("ac,radeonsi import PM4 state from RadeonSI")
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30257>
(cherry picked from commit 0c868aa94a)
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2024-07-19 08:42:01 +02:00 committed by Eric Engestrom
parent 0d06efe0a1
commit 59c48fa36a
2 changed files with 6 additions and 2 deletions

View file

@ -954,7 +954,7 @@
"description": "amd: use a valid size for ac_pm4_state allocation",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "428601095c38bd80f4ed164414f8096edd73832f",
"notes": null

View file

@ -409,7 +409,11 @@ ac_pm4_create_sized(const struct radeon_info *info, bool debug_sqtt,
unsigned max_dw, bool is_compute_queue)
{
struct ac_pm4_state *pm4;
unsigned size = sizeof(*pm4) + 4 * (max_dw - ARRAY_SIZE(pm4->pm4));
unsigned size;
max_dw = MAX2(max_dw, ARRAY_SIZE(pm4->pm4));
size = sizeof(*pm4) + 4 * (max_dw - ARRAY_SIZE(pm4->pm4));
pm4 = (struct ac_pm4_state *)calloc(1, size);
if (pm4) {