broadcom/vc4: Add NULL pointer checking

Submitted by Zhaowei Yuan on Aug. 3, 2018, 10:04 p.m.

Details

Message ID 20180804101448epcas5p2c6cd7f29a70a8c7cdef347a4cb07f4ac~HpuIQ9fA-0914909149epcas5p2M@epcas5p2.samsung.com
State New
Headers show
Series "broadcom/vc4: Add NULL pointer checking" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Zhaowei Yuan Aug. 3, 2018, 10:04 p.m.
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@samsung.com>
---
 src/gallium/drivers/vc4/vc4_uniforms.c | 43 ++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Patch hide | download patch | download mbox

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)

Comments

zhaowei yuan <zhaowei.yuan@samsung.com> writes:

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

We don't need a workaround here, we need to fix the actual problem
instead.  That said, from your bugzilla entry it sounds like it's
already fixed in:

commit 833c4046007f22ce1da0e1c2b89e8f1892f8d38e
Author: Eric Anholt <eric@anholt.net>
Date:   Fri Mar 30 16:04:34 2018 -0700

    nir: Look into uniform structs for samplers when counting num_textures.