[PATCH libdrm 2/4] amdgpu: add count for handle table

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

 



count indicats the total number of key in handle table
max_key becomes the max value of key

Signed-off-by: Junwei Zhang <Jerry.Zhang at amd.com>
---
 amdgpu/handle_table.c | 18 +++++++++++-------
 amdgpu/handle_table.h |  1 +
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/amdgpu/handle_table.c b/amdgpu/handle_table.c
index 15cd476..34e8027 100644
--- a/amdgpu/handle_table.c
+++ b/amdgpu/handle_table.c
@@ -31,34 +31,37 @@
 drm_private int handle_table_insert(struct handle_table *table, uint32_t key,
 				    void *value)
 {
-	if (key >= table->max_key) {
+	if (key >= table->count) {
 		uint32_t alignment = sysconf(_SC_PAGESIZE) / sizeof(void*);
-		uint32_t max_key = ALIGN(key, alignment);
+		uint32_t count = ALIGN(key, alignment);
 		void **values;
 
-		values = realloc(table->values, max_key * sizeof(void *));
+		values = realloc(table->values, count * sizeof(void *));
 		if (!values)
 			return -ENOMEM;
 
-		memset(values + table->max_key, 0, (max_key - table->max_key) *
+		memset(values + table->count, 0, (count - table->count) *
 		       sizeof(void *));
 
-		table->max_key = max_key;
+		table->count = count;
 		table->values = values;
 	}
+	if (key > table->max_key)
+		table->max_key = key;
+
 	table->values[key] = value;
 	return 0;
 }
 
 drm_private void handle_table_remove(struct handle_table *table, uint32_t key)
 {
-	if (key < table->max_key)
+	if (key <= table->max_key)
 		table->values[key] = NULL;
 }
 
 drm_private void *handle_table_lookup(struct handle_table *table, uint32_t key)
 {
-	if (key < table->max_key)
+	if (key <= table->max_key)
 		return table->values[key];
 	else
 		return NULL;
@@ -68,5 +71,6 @@ drm_private void handle_table_fini(struct handle_table *table)
 {
 	free(table->values);
 	table->max_key = 0;
+	table->count = 0;
 	table->values = NULL;
 }
diff --git a/amdgpu/handle_table.h b/amdgpu/handle_table.h
index 461193f..007bb58 100644
--- a/amdgpu/handle_table.h
+++ b/amdgpu/handle_table.h
@@ -29,6 +29,7 @@
 
 struct handle_table {
 	uint32_t	max_key;
+	uint32_t	count;
 	void		**values;
 };
 
-- 
1.9.1



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

  Powered by Linux