intel: Add handle to hashtable before freeing along an error path
authorChris Wilson <chris@chris-wilson.co.uk>
Wed, 8 Mar 2017 21:00:59 +0000 (21:00 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Wed, 8 Mar 2017 21:03:22 +0000 (21:03 +0000)
drm_intel_gem_bo_free() unconditionally attempts to remove the handle
from the hashtable. This goes horribly wrong if we haven't already added
the bo to the hashtable.

Reported-by: Michael Thayer <michael.thayer@oracle.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
intel/intel_bufmgr_gem.c

index b1e6907..e260f2d 100644 (file)
@@ -815,6 +815,10 @@ retry:
                }
 
                bo_gem->gem_handle = create.handle;
+               HASH_ADD(handle_hh, bufmgr_gem->handle_table,
+                        gem_handle, sizeof(bo_gem->gem_handle),
+                        bo_gem);
+
                bo_gem->bo.handle = bo_gem->gem_handle;
                bo_gem->bo.bufmgr = bufmgr;
                bo_gem->bo.align = alignment;
@@ -827,10 +831,6 @@ retry:
                                                         tiling_mode,
                                                         stride))
                        goto err_free;
-
-               HASH_ADD(handle_hh, bufmgr_gem->handle_table,
-                        gem_handle, sizeof(bo_gem->gem_handle),
-                        bo_gem);
        }
 
        bo_gem->name = name;