diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 32adae53670..0986e2eab85 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -173,10 +173,18 @@ key_uint_equal(const void *a, const void *b) } static struct iris_bo * -hash_find_bo(struct hash_table *ht, unsigned int key) +find_and_ref_external_bo(struct hash_table *ht, unsigned int key) { struct hash_entry *entry = _mesa_hash_table_search(ht, &key); - return entry ? (struct iris_bo *) entry->data : NULL; + struct iris_bo *bo = entry ? entry->data : NULL; + + if (bo) { + assert(bo->external); + + iris_bo_reference(bo); + } + + return bo; } /** @@ -628,11 +636,9 @@ iris_bo_gem_create_from_name(struct iris_bufmgr *bufmgr, * provides a sufficiently fast match. */ mtx_lock(&bufmgr->lock); - bo = hash_find_bo(bufmgr->name_table, handle); - if (bo) { - iris_bo_reference(bo); + bo = find_and_ref_external_bo(bufmgr->name_table, handle); + if (bo) goto out; - } struct drm_gem_open open_arg = { .name = handle }; int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_GEM_OPEN, &open_arg); @@ -646,11 +652,9 @@ iris_bo_gem_create_from_name(struct iris_bufmgr *bufmgr, * object from the kernel before by looking through the list * again for a matching gem_handle */ - bo = hash_find_bo(bufmgr->handle_table, open_arg.handle); - if (bo) { - iris_bo_reference(bo); + bo = find_and_ref_external_bo(bufmgr->handle_table, open_arg.handle); + if (bo) goto out; - } bo = bo_calloc(); if (!bo) @@ -1275,11 +1279,9 @@ iris_bo_import_dmabuf(struct iris_bufmgr *bufmgr, int prime_fd) * for named buffers, we must not create two bo's pointing at the same * kernel object */ - bo = hash_find_bo(bufmgr->handle_table, handle); - if (bo) { - iris_bo_reference(bo); + bo = find_and_ref_external_bo(bufmgr->handle_table, handle); + if (bo) goto out; - } bo = bo_calloc(); if (!bo)