amdgpu: add valid function for handle table
PATCH 1/1 amdgpu: add valid function for handle table
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 <[email protected]>
--- amdgpu/handle_table.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
amdgpu/handle_table.c +12 -2
@@ -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 ; }
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx