}
rsc->image.data.bo = panfrost_bo_import(dev, whandle->handle);
+ /* Sometimes an import can fail e.g. on an invalid buffer fd, out of
+ * memory space to mmap it etc.
+ */
+ if (!rsc->image.data.bo) {
+ ralloc_free(rsc);
+ return NULL;
+ }
if (rsc->image.layout.crc_mode == PAN_IMAGE_CRC_OOB)
rsc->image.crc.bo = panfrost_bo_create(dev, rsc->image.layout.crc_size, 0);
bo->ptr.cpu = os_mmap(NULL, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
bo->dev->fd, mmap_bo.offset);
if (bo->ptr.cpu == MAP_FAILED) {
- fprintf(stderr, "mmap failed: %p %m\n", bo->ptr.cpu);
- assert(0);
+ bo->ptr.cpu = NULL;
+ fprintf(stderr,
+ "mmap failed: result=%p size=0x%llx fd=%i offset=0x%llx %m\n",
+ bo->ptr.cpu, (long long)bo->size, bo->dev->fd,
+ (long long)mmap_bo.offset);
}
}
bo->dev = dev;
bo->ptr.gpu = (mali_ptr) get_bo_offset.offset;
bo->size = lseek(fd, 0, SEEK_END);
+ /* Sometimes this can fail and return -1. size of -1 is not
+ * a nice thing for mmap to try mmap. Be more robust also
+ * for zero sized maps and fail nicely too
+ */
+ if ((bo->size == 0) || (bo->size == (size_t)-1)) {
+ pthread_mutex_unlock(&dev->bo_map_lock);
+ return NULL;
+ }
bo->flags = PAN_BO_SHARED;
bo->gem_handle = gem_handle;
- assert(bo->size > 0);
p_atomic_set(&bo->refcnt, 1);
// TODO map and unmap on demand?
panfrost_bo_mmap(bo);