Replace the open-coded self-import check with the drm core helper
drm_gem_prime_self_import(), which performs the same ops and device
match and returns the backing GEM object with a reference.

The force_different_devices selftest hook is preserved by dropping the
returned reference and falling through to the normal import path.

Assisted-by: GitHub-Copilot:claude-opus-4.8
Signed-off-by: Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c 
b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
index b43d34c7d641..9a27c8c82881 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -284,20 +284,17 @@ struct drm_gem_object *i915_gem_prime_import(struct 
drm_device *dev,
        static struct lock_class_key lock_class;
        struct dma_buf_attachment *attach;
        struct drm_i915_gem_object *obj;
+       struct drm_gem_object *gem_obj;
        int ret;
 
-       /* is this one of own objects? */
-       if (dma_buf->ops == &i915_dmabuf_ops) {
-               obj = dma_buf_to_obj(dma_buf);
-               /* is it from our device? */
-               if (obj->base.dev == dev &&
-                   !I915_SELFTEST_ONLY(force_different_devices)) {
-                       /*
-                        * Importing dmabuf exported from out own gem increases
-                        * refcount on gem itself instead of f_count of dmabuf.
-                        */
-                       return &i915_gem_object_get(obj)->base;
-               }
+       /* is this one of our own objects? */
+       gem_obj = drm_gem_prime_self_import(dev, dma_buf, &i915_dmabuf_ops);
+       if (gem_obj) {
+               if (!I915_SELFTEST_ONLY(force_different_devices))
+                       return gem_obj;
+
+               /* Test only: drop the self-import ref and force the slow path. 
*/
+               drm_gem_object_put(gem_obj);
        }
 
        if (i915_gem_object_size_2big(dma_buf->size))
-- 
2.43.0

Reply via email to