summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/display/dc/core/dc_sink.c
diff options
context:
space:
mode:
authorJerry Zuo <Jerry.Zuo@amd.com>2017-07-31 17:10:44 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-09-26 18:16:36 -0400
commite8cd26434df0cd8d97f31aeb4399afcdc37fcfda (patch)
tree26614c3e36f8cb14e10d34a5431c4dcf2efe820f /drivers/gpu/drm/amd/display/dc/core/dc_sink.c
parentf81483c4ccca0d2ceca14ee15564a14f2c34eb2c (diff)
drm/amd/display: Use atomic types for ref_count
Current ref_count inc/dec is not guarded by locks which leads to a raced condition where two threads try to access the variable at the same time. In this case, both might act on the same cached value and inc/dec from the same value, rather than inc/dec by 2. Signed-off-by: Jerry Zuo <Jerry.Zuo@amd.com> Reviewed-by: Harry Wentland <Harry.Wentland@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/display/dc/core/dc_sink.c')
-rw-r--r--drivers/gpu/drm/amd/display/dc/core/dc_sink.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_sink.c b/drivers/gpu/drm/amd/display/dc/core/dc_sink.c
index a83f1243a9d1..7717350297a5 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_sink.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_sink.c
@@ -63,16 +63,16 @@ static bool construct(struct dc_sink *sink, const struct dc_sink_init_data *init
void dc_sink_retain(struct dc_sink *sink)
{
- ASSERT(sink->ref_count > 0);
- ++sink->ref_count;
+ ASSERT(atomic_read(&sink->ref_count) > 0);
+ atomic_inc(&sink->ref_count);
}
void dc_sink_release(struct dc_sink *sink)
{
- ASSERT(sink->ref_count > 0);
- --sink->ref_count;
+ ASSERT(atomic_read(&sink->ref_count) > 0);
+ atomic_dec(&sink->ref_count);
- if (sink->ref_count == 0) {
+ if (atomic_read(&sink->ref_count) == 0) {
destruct(sink);
dm_free(sink);
}
@@ -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;
- ++sink->ref_count;
+ atomic_inc(&sink->ref_count);
return sink;