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>
This commit is contained in:
Yiwei Zhang 2024-03-08 00:55:10 -08:00 committed by Marge Bot
parent f5532f8bab
commit 8af267eb00

View file

@ -807,7 +807,7 @@ vn_queue_submission_setup_batches(struct vn_queue_submission *submit)
* - non-empty: copy batches for adding feedbacks
* - empty: initialize a batch for fence feedback
*/
if (submit->batches) {
if (submit->batch_count) {
memcpy(submit->temp.batches, submit->batches,
vn_get_batch_size(submit) * submit->batch_count);
} else {