Mesa (main): lima: add some checks for potential null pointer dereference
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Feb 11 22:03:20 UTC 2022
Module: Mesa
Branch: main
Commit: 116f01c85356808bae9b7c5ff4962e76e86c4473
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=116f01c85356808bae9b7c5ff4962e76e86c4473
Author: Erico Nunes <nunes.erico at gmail.com>
Date: Fri Feb 4 20:22:17 2022 +0100
lima: add some checks for potential null pointer dereference
scan-build complains about a potential null pointer dereference in
some places around the lima code.
None of those seem to be a real issue as of now, but let's add some
asserts to cover for that and clean up the warning list.
Signed-off-by: Erico Nunes <nunes.erico at gmail.com>
Reviewed-by: Vasily Khoruzhick <anarsoul at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14894>
---
src/gallium/drivers/lima/ir/pp/instr.c | 1 +
src/gallium/drivers/lima/ir/pp/nir.c | 1 +
src/gallium/drivers/lima/ir/pp/ppir.h | 2 ++
src/gallium/drivers/lima/lima_job.c | 9 +++++----
4 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/gallium/drivers/lima/ir/pp/instr.c b/src/gallium/drivers/lima/ir/pp/instr.c
index fc64de8812f..19d53cd2ad0 100644
--- a/src/gallium/drivers/lima/ir/pp/instr.c
+++ b/src/gallium/drivers/lima/ir/pp/instr.c
@@ -193,6 +193,7 @@ bool ppir_instr_insert_node(ppir_instr *instr, ppir_node *node)
if (src->node == node)
break;
}
+ assert(src);
assert(src->node == node);
instr->constant[i] = ic;
diff --git a/src/gallium/drivers/lima/ir/pp/nir.c b/src/gallium/drivers/lima/ir/pp/nir.c
index 816daf7f6f5..12c6c5e3a27 100644
--- a/src/gallium/drivers/lima/ir/pp/nir.c
+++ b/src/gallium/drivers/lima/ir/pp/nir.c
@@ -119,6 +119,7 @@ static void ppir_node_add_src(ppir_compiler *comp, ppir_node *node,
}
}
+ assert(child);
ppir_node_target_assign(ps, child);
}
diff --git a/src/gallium/drivers/lima/ir/pp/ppir.h b/src/gallium/drivers/lima/ir/pp/ppir.h
index de2b54257e8..306d3e2fe02 100644
--- a/src/gallium/drivers/lima/ir/pp/ppir.h
+++ b/src/gallium/drivers/lima/ir/pp/ppir.h
@@ -504,6 +504,7 @@ static inline ppir_node *ppir_node_first_pred(ppir_node *node)
static inline ppir_dest *ppir_node_get_dest(ppir_node *node)
{
+ assert(node);
switch (node->type) {
case ppir_node_type_alu:
return &ppir_node_to_alu(node)->dest;
@@ -520,6 +521,7 @@ static inline ppir_dest *ppir_node_get_dest(ppir_node *node)
static inline int ppir_node_get_src_num(ppir_node *node)
{
+ assert(node);
switch (node->type) {
case ppir_node_type_alu:
return ppir_node_to_alu(node)->num_src;
diff --git a/src/gallium/drivers/lima/lima_job.c b/src/gallium/drivers/lima/lima_job.c
index c3bb29c50ee..3ec53db2d2a 100644
--- a/src/gallium/drivers/lima/lima_job.c
+++ b/src/gallium/drivers/lima/lima_job.c
@@ -543,7 +543,8 @@ lima_generate_pp_stream(struct lima_job *job, int off_x, int off_y,
struct lima_pp_stream_state *ps = &ctx->pp_stream;
struct lima_job_fb_info *fb = &job->fb;
struct lima_screen *screen = lima_screen(ctx->base.screen);
- int i, num_pp = screen->num_pp;
+ int num_pp = screen->num_pp;
+ assert(num_pp > 0);
/* use hilbert_coords to generates 1D to 2D relationship.
* 1D for pp stream index and 2D for plb block x/y on framebuffer.
@@ -565,10 +566,10 @@ lima_generate_pp_stream(struct lima_job *job, int off_x, int off_y,
count = 1 << (dim + dim);
}
- for (i = 0; i < num_pp; i++)
+ for (int i = 0; i < num_pp; i++)
stream[i] = ps->map + ps->offset[i];
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
int x, y;
hilbert_coords(max, i, &x, &y);
if (x < tiled_w && y < tiled_h) {
@@ -589,7 +590,7 @@ lima_generate_pp_stream(struct lima_job *job, int off_x, int off_y,
}
}
- for (i = 0; i < num_pp; i++) {
+ for (int i = 0; i < num_pp; i++) {
stream[i][si[i]++] = 0;
stream[i][si[i]++] = 0xBC000000;
stream[i][si[i]++] = 0;
More information about the mesa-commit
mailing list