From 797e34f65879039aecc0a677c44af0a1185edfd7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 9 Oct 2018 08:55:46 -0600 Subject: [PATCH] svga: change svga_destroy_shader_variant() to return void svga_destroy_shader_variant() itself flushes and retries the command if there's a failure. So no need for the callers to do it. Other callers of the function were already ignoring the return value. This also fixes a corner-case double-free reported by Coverity (and reported by Dave Airlie). Tested with various OpenGL apps. Reviewed-by: Charmaine Lee --- src/gallium/drivers/svga/svga_pipe_fs.c | 7 +------ src/gallium/drivers/svga/svga_pipe_gs.c | 8 +------- src/gallium/drivers/svga/svga_pipe_vs.c | 7 +------ src/gallium/drivers/svga/svga_shader.c | 5 ++--- src/gallium/drivers/svga/svga_shader.h | 2 +- 5 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/gallium/drivers/svga/svga_pipe_fs.c b/src/gallium/drivers/svga/svga_pipe_fs.c index aadfb1a54e1..52366f0f216 100644 --- a/src/gallium/drivers/svga/svga_pipe_fs.c +++ b/src/gallium/drivers/svga/svga_pipe_fs.c @@ -108,12 +108,7 @@ svga_delete_fs_state(struct pipe_context *pipe, void *shader) svga->state.hw_draw.fs = NULL; } - ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant); - if (ret != PIPE_OK) { - svga_context_flush(svga, NULL); - ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant); - assert(ret == PIPE_OK); - } + svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant); } FREE((void *)fs->base.tokens); diff --git a/src/gallium/drivers/svga/svga_pipe_gs.c b/src/gallium/drivers/svga/svga_pipe_gs.c index 2fe5477529f..cee92a0005b 100644 --- a/src/gallium/drivers/svga/svga_pipe_gs.c +++ b/src/gallium/drivers/svga/svga_pipe_gs.c @@ -120,13 +120,7 @@ svga_delete_gs_state(struct pipe_context *pipe, void *shader) svga->state.hw_draw.gs = NULL; } - ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_GS, variant); - if (ret != PIPE_OK) { - svga_context_flush(svga, NULL); - ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_GS, - variant); - assert(ret == PIPE_OK); - } + svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_GS, variant); } FREE((void *)gs->base.tokens); diff --git a/src/gallium/drivers/svga/svga_pipe_vs.c b/src/gallium/drivers/svga/svga_pipe_vs.c index ba87cb43e8f..3b6d2e9ad2f 100644 --- a/src/gallium/drivers/svga/svga_pipe_vs.c +++ b/src/gallium/drivers/svga/svga_pipe_vs.c @@ -199,12 +199,7 @@ svga_delete_vs_state(struct pipe_context *pipe, void *shader) svga->state.hw_draw.vs = NULL; } - ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant); - if (ret != PIPE_OK) { - svga_context_flush(svga, NULL); - ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant); - assert(ret == PIPE_OK); - } + svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant); } FREE((void *)vs->base.tokens); diff --git a/src/gallium/drivers/svga/svga_shader.c b/src/gallium/drivers/svga/svga_shader.c index 7a0bb3db447..22e449835d5 100644 --- a/src/gallium/drivers/svga/svga_shader.c +++ b/src/gallium/drivers/svga/svga_shader.c @@ -541,7 +541,7 @@ svga_new_shader_variant(struct svga_context *svga) } -enum pipe_error +void svga_destroy_shader_variant(struct svga_context *svga, SVGA3dShaderType type, struct svga_shader_variant *variant) @@ -557,6 +557,7 @@ svga_destroy_shader_variant(struct svga_context *svga, /* flush and try again */ svga_context_flush(svga, NULL); ret = SVGA3D_vgpu10_DestroyShader(svga->swc, variant->id); + assert(ret == PIPE_OK); } util_bitmask_clear(svga->shader_id_bm, variant->id); } @@ -583,8 +584,6 @@ svga_destroy_shader_variant(struct svga_context *svga, FREE(variant); svga->hud.num_shaders--; - - return ret; } /* diff --git a/src/gallium/drivers/svga/svga_shader.h b/src/gallium/drivers/svga/svga_shader.h index b80cf181441..68991e72641 100644 --- a/src/gallium/drivers/svga/svga_shader.h +++ b/src/gallium/drivers/svga/svga_shader.h @@ -285,7 +285,7 @@ svga_set_shader(struct svga_context *svga, struct svga_shader_variant * svga_new_shader_variant(struct svga_context *svga); -enum pipe_error +void svga_destroy_shader_variant(struct svga_context *svga, SVGA3dShaderType type, struct svga_shader_variant *variant); -- 2.30.2