panfrost: try to survive start-up alloc fails

If we fail to allocate memory this early on, we would otherwise fall
over and die. This propagates the errors up to the caller.

Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32428>
This commit is contained in:
Erik Faye-Lund 2024-11-14 17:51:14 +01:00 committed by Marge Bot
parent c8a6709cbc
commit 385301db2f
3 changed files with 23 additions and 7 deletions

View file

@ -50,7 +50,7 @@ panfrost_supports_compressed_format(struct panfrost_device *dev,
return dev->compressed_formats & BITFIELD_BIT(texfeat_bit);
}
void
int
panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
{
dev->memctx = memctx;
@ -58,7 +58,7 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
dev->kmod.dev = pan_kmod_dev_create(fd, PAN_KMOD_DEV_FLAG_OWNS_FD, NULL);
if (!dev->kmod.dev) {
close(fd);
return;
return -1;
}
pan_kmod_dev_query_props(dev->kmod.dev, &dev->kmod.props);
@ -120,7 +120,8 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
if (dev->arch < 10) {
dev->tiler_heap = panfrost_bo_create(
dev, 128 * 1024 * 1024, PAN_BO_INVISIBLE | PAN_BO_GROWABLE, "Tiler heap");
assert(dev->tiler_heap);
if (!dev->tiler_heap)
goto err_free_kmod_dev;
}
pthread_mutex_init(&dev->submit_lock, NULL);
@ -128,14 +129,25 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
/* Done once on init */
dev->sample_positions = panfrost_bo_create(
dev, panfrost_sample_positions_buffer_size(), 0, "Sample positions");
assert(dev->sample_positions);
if (!dev->sample_positions)
goto err_free_kmod_dev;
panfrost_upload_sample_positions(dev->sample_positions->ptr.cpu);
return;
return 0;
err_free_kmod_dev:
if (dev->decode_ctx)
pandecode_destroy_context(dev->decode_ctx);
panfrost_bo_unreference(dev->tiler_heap);
panfrost_bo_unreference(dev->sample_positions);
if (dev->kmod.vm)
pan_kmod_vm_destroy(dev->kmod.vm);
pan_kmod_dev_destroy(dev->kmod.dev);
dev->kmod.dev = NULL;
return -1;
}
void

View file

@ -209,7 +209,7 @@ panfrost_device_kmod_version_minor(const struct panfrost_device *dev)
return dev->kmod.dev->driver.version.minor;
}
void panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev);
int panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev);
void panfrost_close_device(struct panfrost_device *dev);

View file

@ -950,7 +950,11 @@ panfrost_create_screen(int fd, const struct pipe_screen_config *config,
debug_get_flags_option("PAN_MESA_DEBUG", panfrost_debug_options, 0);
screen->max_afbc_packing_ratio = debug_get_num_option(
"PAN_MAX_AFBC_PACKING_RATIO", DEFAULT_MAX_AFBC_PACKING_RATIO);
panfrost_open_device(screen, fd, dev);
if (panfrost_open_device(screen, fd, dev)) {
ralloc_free(screen);
return NULL;
}
if (dev->debug & PAN_DBG_NO_AFBC)
dev->has_afbc = false;