From: Dave Airlie <airl...@redhat.com>

Rolling your own reference counting is frowned upon.

Signed-off-by: Dave Airlie <airl...@redhat.com>
---
 drivers/gpu/drm/amd/display/dc/core/dc_surface.c | 19 +++++++++----------
 drivers/gpu/drm/amd/display/dc/dc_hw_types.h     |  4 +---
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_surface.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
index c2168df..0950075 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
@@ -129,18 +129,18 @@ void dc_plane_state_release(struct dc_plane_state 
*plane_state)
 
 void dc_gamma_retain(struct dc_gamma *gamma)
 {
-       ASSERT(atomic_read(&gamma->ref_count) > 0);
-       atomic_inc(&gamma->ref_count);
+       kref_get(&gamma->refcount);
 }
 
-void dc_gamma_release(struct dc_gamma **gamma)
+static void dc_gamma_free(struct kref *kref)
 {
-       ASSERT(atomic_read(&(*gamma)->ref_count) > 0);
-       atomic_dec(&(*gamma)->ref_count);
-
-       if (atomic_read(&(*gamma)->ref_count) == 0)
-               kfree((*gamma));
+       struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
+       kfree(gamma);
+}
 
+void dc_gamma_release(struct dc_gamma **gamma)
+{
+       kref_put(&(*gamma)->refcount, dc_gamma_free);
        *gamma = NULL;
 }
 
@@ -151,8 +151,7 @@ struct dc_gamma *dc_create_gamma()
        if (gamma == NULL)
                goto alloc_fail;
 
-       atomic_inc(&gamma->ref_count);
-
+       kref_init(&gamma->refcount);
        return gamma;
 
 alloc_fail:
diff --git a/drivers/gpu/drm/amd/display/dc/dc_hw_types.h 
b/drivers/gpu/drm/amd/display/dc/dc_hw_types.h
index 94f83cd..4ab1093 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_hw_types.h
+++ b/drivers/gpu/drm/amd/display/dc/dc_hw_types.h
@@ -420,6 +420,7 @@ enum dc_gamma_type {
 };
 
 struct dc_gamma {
+       struct kref refcount;
        enum dc_gamma_type type;
        unsigned int num_entries;
 
@@ -431,9 +432,6 @@ struct dc_gamma {
 
        /* private to DC core */
        struct dc_context *ctx;
-
-       /* private to dc_surface.c */
-       atomic_t ref_count;
 };
 
 /* Used by both ipp amd opp functions*/
-- 
2.9.5

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to