]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/vmwgfx: Fix invalid kref_put callback in vmw_bo_dirty_release
authorBrad Spengler <brad.spengler@opensrcsec.com>
Wed, 7 Jan 2026 17:12:36 +0000 (12:12 -0500)
committerZack Rusin <zack.rusin@broadcom.com>
Thu, 5 Feb 2026 17:43:51 +0000 (12:43 -0500)
The kref_put() call uses (void *)kvfree as the release callback, which
is incorrect. kref_put() expects a function with signature
void (*release)(struct kref *), but kvfree has signature
void (*)(const void *). Calling through an incompatible function pointer
is undefined behavior.

The code only worked by accident because ref_count is the first member
of vmw_bo_dirty, making the kref pointer equal to the struct pointer.

Fix this by adding a proper release callback that uses container_of()
to retrieve the containing structure before freeing.

Fixes: c1962742ffff ("drm/vmwgfx: Use kref in vmw_bo_dirty")
Signed-off-by: Brad Spengler <brad.spengler@opensrcsec.com>
Signed-off-by: Zack Rusin <zack.rusin@broadcom.com>
Cc: Ian Forbes <ian.forbes@broadcom.com>
Link: https://patch.msgid.link/20260107171236.3573118-1-zack.rusin@broadcom.com
drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c

index fd4e76486f2d1b3901c9393a0eb15c2fe2c113cd..45561bc1c9effe68d7676fd5678f458791728a02 100644 (file)
@@ -260,6 +260,13 @@ out_no_dirty:
        return ret;
 }
 
+static void vmw_bo_dirty_free(struct kref *kref)
+{
+       struct vmw_bo_dirty *dirty = container_of(kref, struct vmw_bo_dirty, ref_count);
+
+       kvfree(dirty);
+}
+
 /**
  * vmw_bo_dirty_release - Release a dirty-tracking user from a buffer object
  * @vbo: The buffer object
@@ -274,7 +281,7 @@ void vmw_bo_dirty_release(struct vmw_bo *vbo)
 {
        struct vmw_bo_dirty *dirty = vbo->dirty;
 
-       if (dirty && kref_put(&dirty->ref_count, (void *)kvfree))
+       if (dirty && kref_put(&dirty->ref_count, vmw_bo_dirty_free))
                vbo->dirty = NULL;
 }