drm-shim: Add error handling for bo_init()

Don't assert, return an error.  If we are fuzzing something using
drm-shim, we want to be more like the kernel and return an error
for OoM situation, rather than falling over.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16250>
This commit is contained in:
Rob Clark 2022-04-29 09:17:47 -07:00 committed by Marge Bot
parent c4b5ebe1fc
commit 6c465ad6c7
2 changed files with 7 additions and 3 deletions

View File

@ -301,16 +301,20 @@ drm_shim_ioctl(int fd, unsigned long request, void *arg)
return -EINVAL;
}
void
int
drm_shim_bo_init(struct shim_bo *bo, size_t size)
{
mtx_lock(&shim_device.mem_lock);
bo->mem_addr = util_vma_heap_alloc(&shim_device.mem_heap, size, shim_page_size);
mtx_unlock(&shim_device.mem_lock);
assert(bo->mem_addr);
if (!bo->mem_addr)
return -ENOMEM;
bo->size = size;
return 0;
}
struct shim_bo *

View File

@ -93,7 +93,7 @@ int drm_shim_ioctl(int fd, unsigned long request, void *arg);
void *drm_shim_mmap(struct shim_fd *shim_fd, size_t length, int prot, int flags,
int fd, off64_t offset);
void drm_shim_bo_init(struct shim_bo *bo, size_t size);
int drm_shim_bo_init(struct shim_bo *bo, size_t size);
void drm_shim_bo_get(struct shim_bo *bo);
void drm_shim_bo_put(struct shim_bo *bo);
struct shim_bo *drm_shim_bo_lookup(struct shim_fd *shim_fd, int handle);