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 ff07105bfd99f5f004a855cd2a7b41d69f3f9b9e..c2168dfacc8d60887e41ab54b643b8a144913d6a 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_surface.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_surface.c @@ -161,17 +161,18 @@ struct dc_gamma *dc_create_gamma() void dc_transfer_func_retain(struct dc_transfer_func *tf) { - ASSERT(atomic_read(&tf->ref_count) > 0); - atomic_inc(&tf->ref_count); + kref_get(&tf->refcount); } -void dc_transfer_func_release(struct dc_transfer_func *tf) +static void dc_transfer_func_free(struct kref *kref) { - ASSERT(atomic_read(&tf->ref_count) > 0); - atomic_dec(&tf->ref_count); + struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount); + kfree(tf); +} - if (atomic_read(&tf->ref_count) == 0) - kfree(tf); +void dc_transfer_func_release(struct dc_transfer_func *tf) +{ + kref_put(&tf->refcount, dc_transfer_func_free); } struct dc_transfer_func *dc_create_transfer_func() @@ -181,7 +182,7 @@ struct dc_transfer_func *dc_create_transfer_func() if (tf == NULL) goto alloc_fail; - atomic_inc(&tf->ref_count); + kref_init(&tf->refcount); return tf; diff --git a/drivers/gpu/drm/amd/display/dc/dc.h b/drivers/gpu/drm/amd/display/dc/dc.h index 259ac69185647ae707b65068c634421fdae30e56..f16c545a87ed0a9e77d0e7d929fcdc129faf2796 100644 --- a/drivers/gpu/drm/amd/display/dc/dc.h +++ b/drivers/gpu/drm/amd/display/dc/dc.h @@ -330,11 +330,11 @@ enum dc_transfer_func_predefined { }; struct dc_transfer_func { + struct kref refcount; struct dc_transfer_func_distributed_points tf_pts; enum dc_transfer_func_type type; enum dc_transfer_func_predefined tf; struct dc_context *ctx; - atomic_t ref_count; }; /* diff --git a/drivers/gpu/drm/amd/display/dc/os_types.h b/drivers/gpu/drm/amd/display/dc/os_types.h index 27ed2a61c3c81d5d31c955b4fb7d38a07587d1b6..e0cd5278aae81af1365d2e3067c3db440a5c3e8e 100644 --- a/drivers/gpu/drm/amd/display/dc/os_types.h +++ b/drivers/gpu/drm/amd/display/dc/os_types.h @@ -32,6 +32,8 @@ #include #include +#include + #include "cgs_linux.h" #if defined(__BIG_ENDIAN) && !defined(BIGENDIAN_CPU)