Skip to content

Commit d28bb01

Browse files
unerligerodrigovivi
authored andcommitted
drm/xe: Add ref counting for xe_file
Add ref counting for xe_file. v2: - Add kernel doc for exported functions (Matt) - Instead of xe_file_destroy, export the get/put helpers (Lucas) v3: Fixup the kernel-doc format and description (Matt, Lucas) Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240718210548.3580382-3-umesh.nerlige.ramappa@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> (cherry picked from commit ce8c161) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
1 parent e98a032 commit d28bb01

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

drivers/gpu/drm/xe/xe_device.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
8787
spin_unlock(&xe->clients.lock);
8888

8989
file->driver_priv = xef;
90+
kref_init(&xef->refcount);
91+
9092
return 0;
9193
}
9294

93-
static void xe_file_destroy(struct xe_file *xef)
95+
static void xe_file_destroy(struct kref *ref)
9496
{
97+
struct xe_file *xef = container_of(ref, struct xe_file, refcount);
9598
struct xe_device *xe = xef->xe;
9699

97100
xa_destroy(&xef->exec_queue.xa);
@@ -107,6 +110,32 @@ static void xe_file_destroy(struct xe_file *xef)
107110
kfree(xef);
108111
}
109112

113+
/**
114+
* xe_file_get() - Take a reference to the xe file object
115+
* @xef: Pointer to the xe file
116+
*
117+
* Anyone with a pointer to xef must take a reference to the xe file
118+
* object using this call.
119+
*
120+
* Return: xe file pointer
121+
*/
122+
struct xe_file *xe_file_get(struct xe_file *xef)
123+
{
124+
kref_get(&xef->refcount);
125+
return xef;
126+
}
127+
128+
/**
129+
* xe_file_put() - Drop a reference to the xe file object
130+
* @xef: Pointer to the xe file
131+
*
132+
* Used to drop reference to the xef object
133+
*/
134+
void xe_file_put(struct xe_file *xef)
135+
{
136+
kref_put(&xef->refcount, xe_file_destroy);
137+
}
138+
110139
static void xe_file_close(struct drm_device *dev, struct drm_file *file)
111140
{
112141
struct xe_file *xef = file->driver_priv;
@@ -129,7 +158,7 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
129158
xe_vm_close_and_put(vm);
130159
mutex_unlock(&xef->vm.lock);
131160

132-
xe_file_destroy(xef);
161+
xe_file_put(xef);
133162
}
134163

135164
static const struct drm_ioctl_desc xe_ioctls[] = {

drivers/gpu/drm/xe/xe_device.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,7 @@ static inline bool xe_device_wedged(struct xe_device *xe)
170170

171171
void xe_device_declare_wedged(struct xe_device *xe);
172172

173+
struct xe_file *xe_file_get(struct xe_file *xef);
174+
void xe_file_put(struct xe_file *xef);
175+
173176
#endif

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ struct xe_file {
566566

567567
/** @client: drm client */
568568
struct xe_drm_client *client;
569+
570+
/** @refcount: ref count of this xe file */
571+
struct kref refcount;
569572
};
570573

571574
#endif

0 commit comments

Comments
 (0)