From 74c676509dab180a97d4433bbab2235d94328199 Mon Sep 17 00:00:00 2001 From: Carl Zhang Date: Wed, 6 Aug 2025 15:36:02 +0800 Subject: [PATCH] unreference buffer object should minus to 1 before final release Signed-off-by: Carl Zhang --- media_softlet/linux/common/os/xe/mos_bufmgr_xe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c b/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c index e0f561604a..78c3eb6423 100644 --- a/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c +++ b/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c @@ -801,7 +801,7 @@ drm_export void mos_bo_unreference_xe(struct mos_linux_bo *bo) if (atomic_read(&bo_gem->ref_count) <= 0) return; - if (atomic_dec_and_test(&bo_gem->ref_count)) + if (atomic_add_unless(&bo_gem->ref_count, -1, 1)) { /* release memory associated with this object */ /* Clear any left-over mappings */ @@ -811,9 +811,9 @@ drm_export void mos_bo_unreference_xe(struct mos_linux_bo *bo) __mos_bo_mark_mmaps_incoherent_xe(bo); } - DRMLISTDEL(&bo_gem->name_list); - mos_bo_free_xe(bo); + if (atomic_dec_and_test(&bo_gem->ref_count)) + mos_bo_free_xe(bo); } } @@ -3003,6 +3003,7 @@ mos_bo_free_xe(struct mos_linux_bo *bo) mos_gem_bo_wait_rendering_xe(bo); bufmgr_gem->m_lock.lock(); + DRMLISTDEL(&bo_gem->name_list); if (!bo_gem->is_userptr) {