Module: Mesa
Branch: main
Commit: 45a27adc3b9c45e04945add803de58cc9d285a50
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=45a27adc3b9c45e04945add803de58cc9d285a50

Author: Boris Brezillon <[email protected]>
Date:   Fri Jun 23 09:18:21 2023 +0200

renderonly: 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: ad4d7ca83324 ("kmsro: Fix renderonly_scanout BO aliasing")
Cc: mesa-stable
Signed-off-by: Boris Brezillon <[email protected]>
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23746>

---

 src/gallium/auxiliary/renderonly/renderonly.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/renderonly/renderonly.c 
b/src/gallium/auxiliary/renderonly/renderonly.c
index 386665f25cb..fc09f16a167 100644
--- a/src/gallium/auxiliary/renderonly/renderonly.c
+++ b/src/gallium/auxiliary/renderonly/renderonly.c
@@ -66,7 +66,7 @@ renderonly_create_kms_dumb_buffer_for_resource(struct 
pipe_resource *rsc,
                                                struct renderonly *ro,
                                                struct winsys_handle 
*out_handle)
 {
-   struct renderonly_scanout *scanout;
+   struct renderonly_scanout *scanout = NULL;
    int err;
    struct drm_mode_create_dumb create_dumb = {
       .width = rsc->width0,
@@ -114,6 +114,12 @@ renderonly_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);
 

Reply via email to