winsys/panfrost: Make sure we reset scanout on error in create_kms_dumb_buffer_for_resource()

If an error occured, make sure we reset the scanout object before
leaving, otherwise the next user of this handle will hit the
refcnt == 0 assert.

Fixes: ad4d7ca833 ("kmsro: Fix renderonly_scanout BO aliasing")
Cc: mesa-stable
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Italo Nicola <italonicola@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23746>
This commit is contained in:
Boris Brezillon 2023-06-23 09:18:31 +02:00 committed by Marge Bot
parent 45a27adc3b
commit 7a0033a1c9

View file

@ -45,6 +45,7 @@ panfrost_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
{
/* Find the smallest width alignment that gives us a 64byte aligned stride */
unsigned blk_sz = util_format_get_blocksize(rsc->format);
struct renderonly_scanout *scanout = NULL;
assert(blk_sz);
@ -74,8 +75,6 @@ panfrost_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
if (create_dumb.pitch % 64)
goto free_dumb;
struct renderonly_scanout *scanout;
simple_mtx_lock(&ro->bo_map_lock);
scanout = util_sparse_array_get(&ro->bo_map, create_dumb.handle);
simple_mtx_unlock(&ro->bo_map_lock);
@ -107,6 +106,12 @@ panfrost_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
return scanout;
free_dumb:
/* If an error occured, make sure we reset the scanout object before
* leaving.
*/
if (scanout)
memset(scanout, 0, sizeof(*scanout));
destroy_dumb.handle = create_dumb.handle;
drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);