From 88fc4e26b6c2a35447fde1ee7da5e7d5ff4ff471 Mon Sep 17 00:00:00 2001 From: Alexander Kapshuk Date: Wed, 13 Jan 2021 19:17:02 +0000 Subject: [PATCH] frontends/va/image: Eliminate repetitive code on error paths Removes repetitive code in exit on error paths in the derive image function. Signed-off-by: Alexander Kapshuk Reviewed-by: Thong Thai Part-of: --- src/gallium/frontends/va/image.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/gallium/frontends/va/image.c b/src/gallium/frontends/va/image.c index 7a0d391e470..76cb403ed99 100644 --- a/src/gallium/frontends/va/image.c +++ b/src/gallium/frontends/va/image.c @@ -200,6 +200,7 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image) vlVaSurface *surf; vlVaBuffer *img_buf; VAImage *img; + VAStatus status; struct pipe_screen *screen; struct pipe_surface **surfaces; struct pipe_video_buffer *new_buffer = NULL; @@ -243,10 +244,9 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image) if ((strcmp(derive_interlaced_allowlist[i], proc) == 0)) break; - if (i >= ARRAY_SIZE(derive_interlaced_allowlist)) - return VA_STATUS_ERROR_OPERATION_FAILED; - - if (!screen->get_video_param(screen, PIPE_VIDEO_PROFILE_UNKNOWN, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, + if (i >= ARRAY_SIZE(derive_interlaced_allowlist) || + !screen->get_video_param(screen, PIPE_VIDEO_PROFILE_UNKNOWN, + PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE)) return VA_STATUS_ERROR_OPERATION_FAILED; } @@ -318,9 +318,8 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image) /* not all devices support non-interlaced buffers */ if (!new_buffer) { - FREE(img); - mtx_unlock(&drv->mutex); - return VA_STATUS_ERROR_OPERATION_FAILED; + status = VA_STATUS_ERROR_OPERATION_FAILED; + goto exit_on_error; } /* convert the interlaced to the progressive */ @@ -357,16 +356,14 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image) default: /* VaDeriveImage only supports contiguous planes. But there is now a more generic api vlVaExportSurfaceHandle. */ - FREE(img); - mtx_unlock(&drv->mutex); - return VA_STATUS_ERROR_OPERATION_FAILED; + status = VA_STATUS_ERROR_OPERATION_FAILED; + goto exit_on_error; } img_buf = CALLOC(1, sizeof(vlVaBuffer)); if (!img_buf) { - FREE(img); - mtx_unlock(&drv->mutex); - return VA_STATUS_ERROR_ALLOCATION_FAILED; + status = VA_STATUS_ERROR_ALLOCATION_FAILED; + goto exit_on_error; } img->image_id = handle_table_add(drv->htab, img); @@ -384,6 +381,11 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image) *image = *img; return VA_STATUS_SUCCESS; + +exit_on_error: + FREE(img); + mtx_unlock(&drv->mutex); + return status; } VAStatus