venus: fix ffb batch prepare for a corner case and avoid a memcpy UB

Batches must be ignored if batch count is zero, so all batch inspections
have to be gated behind batch count. For memcpy, it's UB if either src
or dst is NULL even when size is zero.

Side note:
- For original commit, this fixes just the memcpy UB
- For current codes, this fixes to not skip ffb batch prepare

Fixes: 493a3b5cda ("venus: refactor batch submission fixup")
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28071>
(cherry picked from commit 8af267eb00)
This commit is contained in:
Yiwei Zhang 2024-03-08 00:55:10 -08:00 committed by Eric Engestrom
parent 4364f09974
commit 5e8ca5d067
2 changed files with 2 additions and 2 deletions

View file

@ -364,7 +364,7 @@
"description": "venus: fix ffb batch prepare for a corner case and avoid a memcpy UB",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "493a3b5cdaf038d757198085838819472618f76d",
"notes": null

View file

@ -857,7 +857,7 @@ vn_queue_submission_setup_batches(struct vn_queue_submission *submit)
* to modify cmd buffer.
* Only needed for non-empty submissions
*/
if (submit->batches) {
if (submit->batch_count) {
memcpy(submit->temp.batches, submit->batches,
batch_size * submit->batch_count);
}