When insert or lookup a handle in table,
it needs to check if the handle is vaild or not.

Sometimes it may find a non-existing bo in table

Signed-off-by: Junwei Zhang <jerry.zh...@amd.com>
---
 amdgpu/handle_table.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/amdgpu/handle_table.c b/amdgpu/handle_table.c
index 9acc44d..d089472 100644
--- a/amdgpu/handle_table.c
+++ b/amdgpu/handle_table.c
@@ -26,6 +26,12 @@
 #include <errno.h>
 #include "handle_table.h"
 #include "util_math.h"
+#include <stdbool.h>
+
+drm_private static bool handle_table_valid(struct handle_table *table, 
uint32_t key)
+{
+       return key < table->max_key;
+}
 
 drm_private int handle_table_insert(struct handle_table *table, uint32_t key,
                                    void *value)
@@ -50,10 +56,14 @@ drm_private int handle_table_insert(struct handle_table 
*table, uint32_t key,
 
 drm_private void handle_table_remove(struct handle_table *table, uint32_t key)
 {
-       table->values[key] = NULL;
+       if (handle_table_valid(table, key))
+               table->values[key] = NULL;
 }
 
 drm_private void *handle_table_lockup(struct handle_table *table, uint32_t key)
 {
-       return table->values[key];
+       if (handle_table_valid(table, key))
+               return table->values[key];
+       else
+               return NULL;
 }
-- 
1.9.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to