amdgpu/dc: convert dc_sink to kref.
authorDave Airlie <airlied@redhat.com>
Tue, 3 Oct 2017 02:39:01 +0000 (12:39 +1000)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 6 Oct 2017 17:10:08 +0000 (13:10 -0400)
Refcounts use krefs.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/core/dc_sink.c
drivers/gpu/drm/amd/display/dc/dc.h

index 3d620d3d06723b5b5ff9fa4a3eb3c5c3db9619b1..25fae38409aba5f72b0ced6458ea1ef3481e7f13 100644 (file)
@@ -63,19 +63,19 @@ static bool construct(struct dc_sink *sink, const struct dc_sink_init_data *init
 
 void dc_sink_retain(struct dc_sink *sink)
 {
-       ASSERT(atomic_read(&sink->ref_count) > 0);
-       atomic_inc(&sink->ref_count);
+       kref_get(&sink->refcount);
 }
 
-void dc_sink_release(struct dc_sink *sink)
+static void dc_sink_free(struct kref *kref)
 {
-       ASSERT(atomic_read(&sink->ref_count) > 0);
-       atomic_dec(&sink->ref_count);
+       struct dc_sink *sink = container_of(kref, struct dc_sink, refcount);
+       destruct(sink);
+       kfree(sink);
+}
 
-       if (atomic_read(&sink->ref_count) == 0) {
-               destruct(sink);
-               kfree(sink);
-       }
+void dc_sink_release(struct dc_sink *sink)
+{
+       kref_put(&sink->refcount, dc_sink_free);
 }
 
 struct dc_sink *dc_sink_create(const struct dc_sink_init_data *init_params)
@@ -88,7 +88,7 @@ struct dc_sink *dc_sink_create(const struct dc_sink_init_data *init_params)
        if (false == construct(sink, init_params))
                goto construct_fail;
 
-       atomic_inc(&sink->ref_count);
+       kref_init(&sink->refcount);
 
        return sink;
 
index 97f6f34f3d22df105ec1380549f38d2efcaa6d46..4ff543826476c469fb530cfe06fce08dd0636f7f 100644 (file)
@@ -971,7 +971,7 @@ struct dc_sink {
        struct dc_context *ctx;
 
        /* private to dc_sink.c */
-       atomic_t ref_count;
+       struct kref refcount;
 };
 
 void dc_sink_retain(struct dc_sink *sink);