From f9d1a50d8d02067a7356a8e095fe25a097654550 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 9 Oct 2024 12:38:52 +0200 Subject: [PATCH] frontends/va: Fix some small coverity issues * 1547216 Operands don't affect result - PRESET_MODE_HIGH_QUALITY is maximum value * 1255678 Dereference after null check - no need to check against NULL because the data can only be NULL when the array is empty (size == 0) * 1619397 Unsigned compared against 0 - check >= 0 is always true in vlVaAddRawHeader * 1468885 Dereference null return value - add NULL check for buffers in vlVaRenderPicture Acked-by: Leo Liu Part-of: --- src/gallium/frontends/va/picture.c | 9 ++++++--- src/gallium/frontends/va/surface.c | 3 --- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gallium/frontends/va/picture.c b/src/gallium/frontends/va/picture.c index c35e7e427bb..476acf0c3e9 100644 --- a/src/gallium/frontends/va/picture.c +++ b/src/gallium/frontends/va/picture.c @@ -218,8 +218,7 @@ vlVaHandleVAEncMiscParameterTypeQualityLevel(struct pipe_enc_quality_modes *p, v p->pre_encode_mode = PREENCODING_MODE_DEFAULT; p->vbaq_mode = VBAQ_AUTO; } else { - p->preset_mode = in->preset_mode > PRESET_MODE_HIGH_QUALITY - ? PRESET_MODE_HIGH_QUALITY : in->preset_mode; + p->preset_mode = in->preset_mode; p->pre_encode_mode = in->pre_encode_mode; p->vbaq_mode = in->vbaq_mode; } @@ -1004,6 +1003,10 @@ vlVaRenderPicture(VADriverContextP ctx, VAContextID context_id, VABufferID *buff for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; ++i) { vlVaBuffer *buf = handle_table_get(drv->htab, buffers[i]); + if (!buf) { + mtx_unlock(&drv->mutex); + return VA_STATUS_ERROR_INVALID_BUFFER; + } switch (buf->type) { case VAPictureParameterBufferType: @@ -1402,7 +1405,7 @@ vlVaAddRawHeader(struct util_dynarray *headers, uint8_t type, uint32_t size, memcpy(header.buffer, buf, emulation_bytes_start); for (uint32_t i = emulation_bytes_start; i < size; i++) { uint8_t byte = buf[i]; - if (num_zeros >= 2 && byte >= 0x00 && byte <= 0x03) { + if (num_zeros >= 2 && byte <= 0x03) { header.buffer[pos++] = 0x03; num_zeros = 0; } diff --git a/src/gallium/frontends/va/surface.c b/src/gallium/frontends/va/surface.c index 8281c113f05..4a00ace74d9 100644 --- a/src/gallium/frontends/va/surface.c +++ b/src/gallium/frontends/va/surface.c @@ -345,9 +345,6 @@ vlVaPutSubpictures(vlVaSurface *surf, vlVaDriver *drv, vlVaSubpicture *sub; int i; - if (!(surf->subpics.data || surf->subpics.size)) - return VA_STATUS_SUCCESS; - for (i = 0; i < surf->subpics.size/sizeof(vlVaSubpicture *); i++) { struct pipe_blend_state blend; void *blend_state;