Skip to content

Commit 211ecfa

Browse files
Brad Spenglerzackr
authored andcommitted
drm/vmwgfx: Fix invalid kref_put callback in vmw_bo_dirty_release
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: c196274 ("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
1 parent 40b24d9 commit 211ecfa

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ int vmw_bo_dirty_add(struct vmw_bo *vbo)
260260
return ret;
261261
}
262262

263+
static void vmw_bo_dirty_free(struct kref *kref)
264+
{
265+
struct vmw_bo_dirty *dirty = container_of(kref, struct vmw_bo_dirty, ref_count);
266+
267+
kvfree(dirty);
268+
}
269+
263270
/**
264271
* vmw_bo_dirty_release - Release a dirty-tracking user from a buffer object
265272
* @vbo: The buffer object
@@ -274,7 +281,7 @@ void vmw_bo_dirty_release(struct vmw_bo *vbo)
274281
{
275282
struct vmw_bo_dirty *dirty = vbo->dirty;
276283

277-
if (dirty && kref_put(&dirty->ref_count, (void *)kvfree))
284+
if (dirty && kref_put(&dirty->ref_count, vmw_bo_dirty_free))
278285
vbo->dirty = NULL;
279286
}
280287

0 commit comments

Comments
 (0)