Commit 5c58ab0b authored by Dave Airlie's avatar Dave Airlie Committed by Alex Deucher

amdgpu/dc: convert dc_gamma to kref reference counting.

Rolling your own reference counting is frowned upon.
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
Reviewed-by: default avatarHarry Wentland <harry.wentland@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 93052132
...@@ -129,18 +129,18 @@ void dc_plane_state_release(struct dc_plane_state *plane_state) ...@@ -129,18 +129,18 @@ void dc_plane_state_release(struct dc_plane_state *plane_state)
void dc_gamma_retain(struct dc_gamma *gamma) void dc_gamma_retain(struct dc_gamma *gamma)
{ {
ASSERT(atomic_read(&gamma->ref_count) > 0); kref_get(&gamma->refcount);
atomic_inc(&gamma->ref_count);
} }
void dc_gamma_release(struct dc_gamma **gamma) static void dc_gamma_free(struct kref *kref)
{ {
ASSERT(atomic_read(&(*gamma)->ref_count) > 0); struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
atomic_dec(&(*gamma)->ref_count); kfree(gamma);
}
if (atomic_read(&(*gamma)->ref_count) == 0)
kfree((*gamma));
void dc_gamma_release(struct dc_gamma **gamma)
{
kref_put(&(*gamma)->refcount, dc_gamma_free);
*gamma = NULL; *gamma = NULL;
} }
...@@ -151,8 +151,7 @@ struct dc_gamma *dc_create_gamma() ...@@ -151,8 +151,7 @@ struct dc_gamma *dc_create_gamma()
if (gamma == NULL) if (gamma == NULL)
goto alloc_fail; goto alloc_fail;
atomic_inc(&gamma->ref_count); kref_init(&gamma->refcount);
return gamma; return gamma;
alloc_fail: alloc_fail:
......
...@@ -420,6 +420,7 @@ enum dc_gamma_type { ...@@ -420,6 +420,7 @@ enum dc_gamma_type {
}; };
struct dc_gamma { struct dc_gamma {
struct kref refcount;
enum dc_gamma_type type; enum dc_gamma_type type;
unsigned int num_entries; unsigned int num_entries;
...@@ -431,9 +432,6 @@ struct dc_gamma { ...@@ -431,9 +432,6 @@ struct dc_gamma {
/* private to DC core */ /* private to DC core */
struct dc_context *ctx; struct dc_context *ctx;
/* private to dc_surface.c */
atomic_t ref_count;
}; };
/* Used by both ipp amd opp functions*/ /* Used by both ipp amd opp functions*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment