From 59c48fa36a2cc731bdcb72404f548bedf5fe54c2 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Fri, 19 Jul 2024 08:42:01 +0200 Subject: [PATCH] amd: use a valid size for ac_pm4_state allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If max_dw is smaller than the pm4 array the allocation size would be smaller than sizeof(ac_pm4_state). Fixes: 428601095c3 ("ac,radeonsi import PM4 state from RadeonSI") Reviewed-by: Samuel Pitoiset Reviewed-by: Marek Olšák Part-of: (cherry picked from commit 0c868aa94a218b99e13f31bf0e83a43de01e0da5) --- .pick_status.json | 2 +- src/amd/common/ac_pm4.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 813bbd11f8d..341573861d8 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -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 diff --git a/src/amd/common/ac_pm4.c b/src/amd/common/ac_pm4.c index bbac8cccfac..df9a6d9448c 100644 --- a/src/amd/common/ac_pm4.c +++ b/src/amd/common/ac_pm4.c @@ -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) {