amdgpu/dc: convert dc_transfer to use a kref.
Rolling your own atomic ref counts is frowned upon. 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>
This commit is contained in:
committed by
Alex Deucher
parent
5d15ae23f8
commit
9305213256
@@ -161,17 +161,18 @@ alloc_fail:
|
|||||||
|
|
||||||
void dc_transfer_func_retain(struct dc_transfer_func *tf)
|
void dc_transfer_func_retain(struct dc_transfer_func *tf)
|
||||||
{
|
{
|
||||||
ASSERT(atomic_read(&tf->ref_count) > 0);
|
kref_get(&tf->refcount);
|
||||||
atomic_inc(&tf->ref_count);
|
}
|
||||||
|
|
||||||
|
static void dc_transfer_func_free(struct kref *kref)
|
||||||
|
{
|
||||||
|
struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
|
||||||
|
kfree(tf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dc_transfer_func_release(struct dc_transfer_func *tf)
|
void dc_transfer_func_release(struct dc_transfer_func *tf)
|
||||||
{
|
{
|
||||||
ASSERT(atomic_read(&tf->ref_count) > 0);
|
kref_put(&tf->refcount, dc_transfer_func_free);
|
||||||
atomic_dec(&tf->ref_count);
|
|
||||||
|
|
||||||
if (atomic_read(&tf->ref_count) == 0)
|
|
||||||
kfree(tf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dc_transfer_func *dc_create_transfer_func()
|
struct dc_transfer_func *dc_create_transfer_func()
|
||||||
@@ -181,7 +182,7 @@ struct dc_transfer_func *dc_create_transfer_func()
|
|||||||
if (tf == NULL)
|
if (tf == NULL)
|
||||||
goto alloc_fail;
|
goto alloc_fail;
|
||||||
|
|
||||||
atomic_inc(&tf->ref_count);
|
kref_init(&tf->refcount);
|
||||||
|
|
||||||
return tf;
|
return tf;
|
||||||
|
|
||||||
|
|||||||
@@ -330,11 +330,11 @@ enum dc_transfer_func_predefined {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct dc_transfer_func {
|
struct dc_transfer_func {
|
||||||
|
struct kref refcount;
|
||||||
struct dc_transfer_func_distributed_points tf_pts;
|
struct dc_transfer_func_distributed_points tf_pts;
|
||||||
enum dc_transfer_func_type type;
|
enum dc_transfer_func_type type;
|
||||||
enum dc_transfer_func_predefined tf;
|
enum dc_transfer_func_predefined tf;
|
||||||
struct dc_context *ctx;
|
struct dc_context *ctx;
|
||||||
atomic_t ref_count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <drm/drmP.h>
|
#include <drm/drmP.h>
|
||||||
|
|
||||||
|
#include <linux/kref.h>
|
||||||
|
|
||||||
#include "cgs_linux.h"
|
#include "cgs_linux.h"
|
||||||
|
|
||||||
#if defined(__BIG_ENDIAN) && !defined(BIGENDIAN_CPU)
|
#if defined(__BIG_ENDIAN) && !defined(BIGENDIAN_CPU)
|
||||||
|
|||||||
Reference in New Issue
Block a user