File 0137-drm-Release-driver-tracking-before-making-the-object.patch of Package drm.openSUSE_Leap_42.3_Update

From ce66f629ad828168ed13250eaa7d3a60124d753e Mon Sep 17 00:00:00 2001
From: Chris Wilson <>
Date: Sat, 19 Aug 2017 13:05:58 +0100
Subject: [PATCH] drm: Release driver tracking before making the object available again
Mime-version: 1.0
Content-type: text/plain; charset=UTF-8
Content-transfer-encoding: 8bit
Git-commit: fe4600a548f2763dec91b3b27a1245c370ceee2a
Patch-mainline: 4.13-rc7
References: bsc#1041744

commit fe4600a548f2763dec91b3b27a1245c370ceee2a upstream.

This is the same bug as we fixed in commit f6cd7daecff5 ("drm: Release
driver references to handle before making it available again"), but now
the exposure is via the PRIME lookup tables. If we remove the
object/handle from the PRIME lut, then a new request for the same
object/fd will generate a new handle, thus for a short window that
object is known to userspace by two different handles. Fix this by
releasing the driver tracking before PRIME.

Fixes: 0ff926c7d4f0 ("drm/prime: add exported buffers to current fprivs
imported buffer list (v2)")

Signed-off-by: Chris Wilson <>
Cc: David Airlie <>
Cc: Daniel Vetter <>
Cc: Rob Clark <>
Cc: Ville Syrjälä <>
Cc: Thierry Reding <>
Reviewed-by: Daniel Vetter <>
Signed-off-by: Joonas Lahtinen <>
Signed-off-by: Greg Kroah-Hartman <>
Acked-by: Takashi Iwai <>

 drivers/gpu/drm/drm_gem.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -255,13 +255,13 @@ drm_gem_object_release_handle(int id, vo
 	struct drm_gem_object *obj = ptr;
 	struct drm_device *dev = obj->dev;
+	if (dev->driver->gem_close_object)
+		dev->driver->gem_close_object(obj, file_priv);
 	if (drm_core_check_feature(dev, DRIVER_PRIME))
 		drm_gem_remove_prime_handles(obj, file_priv);
 	drm_vma_node_revoke(&obj->vma_node, file_priv);
-	if (dev->driver->gem_close_object)
-		dev->driver->gem_close_object(obj, file_priv);
 	return 0;