From f61f81e90e264df6f5c72f07e81cff91fc79bdf7 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Wed, 30 Mar 2016 10:59:36 -0500 Subject: drm_gralloc: pipe: add error handling for NULL load_pipe_screen Check load_pipe_screen for NULL and return in case dlsym returns a NULL pointer. This can happen if the correct gallium driver is not enabled. Signed-off-by: Rob Herring --- gralloc_drm_pipe.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gralloc_drm_pipe.c b/gralloc_drm_pipe.c index e44293c..5cc7dc8 100644 --- a/gralloc_drm_pipe.c +++ b/gralloc_drm_pipe.c @@ -386,18 +386,16 @@ struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *na pthread_mutex_init(&pm->mutex, NULL); pm->gallium = dlopen(DRI_LIBRARY_PATH"/gallium_dri.so", RTLD_NOW | RTLD_GLOBAL); - if (!pm->gallium) { - FREE(pm); - return NULL; - } + if (!pm->gallium) + goto err_open; + load_pipe_screen = dlsym(pm->gallium, "load_pipe_screen"); + if (!load_pipe_screen) + goto err_load; pm->screen = load_pipe_screen(&pm->dev, fd); - if (!pm->screen) { - dlclose(pm->gallium); - FREE(pm); - return NULL; - } + if (!pm->screen) + goto err_load; pm->base.destroy = pipe_destroy; pm->base.init_kms_features = pipe_init_kms_features; @@ -408,4 +406,10 @@ struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *na pm->base.blit = pipe_blit; return &pm->base; + +err_load: + dlclose(pm->gallium); +err_open: + FREE(pm); + return NULL; } -- cgit v1.1