Skip to content

Commit c196274

Browse files
en4bzzackr
authored andcommitted
drm/vmwgfx: Use kref in vmw_bo_dirty
Rather than using an ad hoc reference count use kref which is atomic and has underflow warnings. Signed-off-by: Ian Forbes <ian.forbes@broadcom.com> Signed-off-by: Zack Rusin <zack.rusin@broadcom.com> Link: https://patch.msgid.link/20251030193640.153697-1-ian.forbes@broadcom.com
1 parent 32b415a commit c196274

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ enum vmw_bo_dirty_method {
3232

3333
/**
3434
* struct vmw_bo_dirty - Dirty information for buffer objects
35+
* @ref_count: Reference count for this structure. Must be first member!
3536
* @start: First currently dirty bit
3637
* @end: Last currently dirty bit + 1
3738
* @method: The currently used dirty method
3839
* @change_count: Number of consecutive method change triggers
39-
* @ref_count: Reference count for this structure
4040
* @bitmap_size: The size of the bitmap in bits. Typically equal to the
4141
* nuber of pages in the bo.
4242
* @bitmap: A bitmap where each bit represents a page. A set bit means a
4343
* dirty page.
4444
*/
4545
struct vmw_bo_dirty {
46+
struct kref ref_count;
4647
unsigned long start;
4748
unsigned long end;
4849
enum vmw_bo_dirty_method method;
4950
unsigned int change_count;
50-
unsigned int ref_count;
5151
unsigned long bitmap_size;
5252
unsigned long bitmap[];
5353
};
@@ -221,7 +221,7 @@ int vmw_bo_dirty_add(struct vmw_bo *vbo)
221221
int ret;
222222

223223
if (dirty) {
224-
dirty->ref_count++;
224+
kref_get(&dirty->ref_count);
225225
return 0;
226226
}
227227

@@ -235,7 +235,7 @@ int vmw_bo_dirty_add(struct vmw_bo *vbo)
235235
dirty->bitmap_size = num_pages;
236236
dirty->start = dirty->bitmap_size;
237237
dirty->end = 0;
238-
dirty->ref_count = 1;
238+
kref_init(&dirty->ref_count);
239239
if (num_pages < PAGE_SIZE / sizeof(pte_t)) {
240240
dirty->method = VMW_BO_DIRTY_PAGETABLE;
241241
} else {
@@ -274,10 +274,8 @@ void vmw_bo_dirty_release(struct vmw_bo *vbo)
274274
{
275275
struct vmw_bo_dirty *dirty = vbo->dirty;
276276

277-
if (dirty && --dirty->ref_count == 0) {
278-
kvfree(dirty);
277+
if (dirty && kref_put(&dirty->ref_count, (void *)kvfree))
279278
vbo->dirty = NULL;
280-
}
281279
}
282280

283281
/**

0 commit comments

Comments
 (0)