[PATCH libdrm] amdgpu: add valid function for handle table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.Zhang at 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



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux