[Mesa-dev] [PATCH] broadcom/vc4: Add NULL pointer checking

zhaowei yuan zhaowei.yuan at samsung.com
Fri Aug 3 22:04:57 UTC 2018


In some cases, texstate->textures and texstate->samplers cann't
be set properly, add NULL pointer checking here to protect program
from crashed

Signed-off-by: zhaowei yuan <zhaowei.yuan at samsung.com>
---
 src/gallium/drivers/vc4/vc4_uniforms.c | 43 ++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/gallium/drivers/vc4/vc4_uniforms.c b/src/gallium/drivers/vc4/vc4_uniforms.c
index 8a43517..51cb2ff 100644
--- a/src/gallium/drivers/vc4/vc4_uniforms.c
+++ b/src/gallium/drivers/vc4/vc4_uniforms.c
@@ -35,6 +35,11 @@ write_texture_p0(struct vc4_job *job,
 {
         struct vc4_sampler_view *sview =
                 vc4_sampler_view(texstate->textures[unit]);
+        if (!sview) {
+                fprintf(stderr, "Empty textures\n");
+                return;
+        }
+
         struct vc4_resource *rsc = vc4_resource(sview->texture);
 
         cl_reloc(job, &job->uniforms, uniforms, rsc->bo, sview->texture_p0);
@@ -48,8 +53,17 @@ write_texture_p1(struct vc4_job *job,
 {
         struct vc4_sampler_view *sview =
                 vc4_sampler_view(texstate->textures[unit]);
+        if (!sview) {
+                fprintf(stderr, "Empty textures\n");
+                return;
+        }
+
         struct vc4_sampler_state *sampler =
                 vc4_sampler_state(texstate->samplers[unit]);
+        if (!sampler) {
+                fprintf(stderr, "Empty samplers\n");
+                return;
+        }
 
         cl_aligned_u32(uniforms, sview->texture_p1 | sampler->texture_p1);
 }
@@ -62,6 +76,11 @@ write_texture_p2(struct vc4_job *job,
 {
         uint32_t unit = data & 0xffff;
         struct pipe_sampler_view *texture = texstate->textures[unit];
+        if (!texture) {
+                fprintf(stderr, "Empty textures\n");
+                return;
+        }
+
         struct vc4_resource *rsc = vc4_resource(texture->texture);
 
         cl_aligned_u32(uniforms,
@@ -79,6 +98,10 @@ write_texture_first_level(struct vc4_job *job,
 {
         uint32_t unit = data & 0xffff;
         struct pipe_sampler_view *texture = texstate->textures[unit];
+        if (!texture) {
+                fprintf(stderr, "Empty textures\n");
+                return;
+        }
 
         cl_aligned_f(uniforms, texture->u.tex.first_level);
 }
@@ -90,6 +113,11 @@ write_texture_msaa_addr(struct vc4_job *job,
                         uint32_t unit)
 {
         struct pipe_sampler_view *texture = texstate->textures[unit];
+        if (!texture) {
+                fprintf(stderr, "Empty textures\n");
+                return;
+        }
+
         struct vc4_resource *rsc = vc4_resource(texture->texture);
 
         cl_aligned_reloc(job, &job->uniforms, uniforms, rsc->bo, 0);
@@ -110,7 +138,17 @@ write_texture_border_color(struct vc4_job *job,
                            uint32_t unit)
 {
         struct pipe_sampler_state *sampler = texstate->samplers[unit];
+        if (!sampler) {
+                fprintf(stderr, "Empty samplers\n");
+                return;
+        }
+
         struct pipe_sampler_view *texture = texstate->textures[unit];
+        if (!texture) {
+                fprintf(stderr, "Empty textures\n");
+                return;
+        }
+
         struct vc4_resource *rsc = vc4_resource(texture->texture);
         union util_color uc;
 
@@ -176,6 +214,11 @@ get_texrect_scale(struct vc4_texture_stateobj *texstate,
                   uint32_t data)
 {
         struct pipe_sampler_view *texture = texstate->textures[data];
+        if (!texture) {
+                fprintf(stderr, "Empty textures\n");
+                return 0;
+        }
+
         uint32_t dim;
 
         if (contents == QUNIFORM_TEXRECT_SCALE_X)
-- 
1.9.1



More information about the mesa-dev mailing list