Mesa (main): drm-shim: Add error handling for bo_init()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 2 20:19:56 UTC 2022


Module: Mesa
Branch: main
Commit: 6c465ad6c76d804e0d08f9f089f2b74dd773153d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6c465ad6c76d804e0d08f9f089f2b74dd773153d

Author: Rob Clark <robdclark at chromium.org>
Date:   Fri Apr 29 09:17:47 2022 -0700

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 at chromium.org>
Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16250>

---

 src/drm-shim/device.c   | 8 ++++++--
 src/drm-shim/drm_shim.h | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/drm-shim/device.c b/src/drm-shim/device.c
index ba1cc907f5e..9ec1f274ea5 100644
--- a/src/drm-shim/device.c
+++ b/src/drm-shim/device.c
@@ -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 *
diff --git a/src/drm-shim/drm_shim.h b/src/drm-shim/drm_shim.h
index 95cce8f4372..4eda0f15030 100644
--- a/src/drm-shim/drm_shim.h
+++ b/src/drm-shim/drm_shim.h
@@ -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);



More information about the mesa-commit mailing list