amdgpu: Use bo_release to free DRI images.

Previously these would get leaked if we had multiple bo structs
pointing to the same image/GEM BO as each has their own DRI image,
but bo_destroy only gets called on the last struct.

To mitigate this we have a new callback for every struct where we
can free the DRI image.

BUG=b:185869479
TEST=Repeatedly open/close camera app on Grunt.

Change-Id: I6188346b5bf9e5cbbbbf32a3db621a3fe0276d4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3270684
Tested-by: Bas Nieuwenhuizen <basni@chromium.org>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Bas Nieuwenhuizen <basni@chromium.org>
diff --git a/amdgpu.c b/amdgpu.c
index 3ebf1ab..f0053d6 100644
--- a/amdgpu.c
+++ b/amdgpu.c
@@ -631,6 +631,14 @@
 		return drv_prime_bo_import(bo, data);
 }
 
+static int amdgpu_release_bo(struct bo *bo)
+{
+	if (bo->priv)
+		return dri_bo_release(bo);
+
+	return 0;
+}
+
 static int amdgpu_destroy_bo(struct bo *bo)
 {
 	if (bo->priv)
@@ -780,6 +788,7 @@
 	.close = amdgpu_close,
 	.bo_create = amdgpu_create_bo,
 	.bo_create_with_modifiers = amdgpu_create_bo_with_modifiers,
+	.bo_release = amdgpu_release_bo,
 	.bo_destroy = amdgpu_destroy_bo,
 	.bo_import = amdgpu_import_bo,
 	.bo_map = amdgpu_map_bo,