Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d620c93a authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Alistair Delva
Browse files

UPSTREAM: drm/virtio: Handle error from virtio_gpu_resource_id_get



ida_alloc() can return -ENOMEM in the highly unlikely case we run out
of memory.  The current code creates an object with an invalid ID.

Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20181030165352.13065-1-willy@infradead.org


Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 556c62e85f9b97139c1b3f6f1585fcee0bc3eb6a)
Signed-off-by: default avatarGreg Hartman <ghartman@google.com>
BUG: 139386237
Change-Id: I0bc83d49fe6b40b6fb5d0e9b1da3cdf64b48f5b3
parent 93d74d36
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -25,11 +25,16 @@

#include "virtgpu_drv.h"

static void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
				       uint32_t *resid)
{
	int handle = ida_alloc_min(&vgdev->resource_ida, 1, GFP_KERNEL);

	if (handle < 0)
		return handle;

	*resid = handle;
	return 0;
}

static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
@@ -92,7 +97,11 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
	bo = kzalloc(sizeof(struct virtio_gpu_object), GFP_KERNEL);
	if (bo == NULL)
		return -ENOMEM;
	virtio_gpu_resource_id_get(vgdev, &bo->hw_res_handle);
	ret = virtio_gpu_resource_id_get(vgdev, &bo->hw_res_handle);
	if (ret < 0) {
		kfree(bo);
		return ret;
	}
	size = roundup(size, PAGE_SIZE);
	ret = drm_gem_object_init(vgdev->ddev, &bo->gem_base, size);
	if (ret != 0) {