diff mbox

gpu: ion: Copy name string in client and heap create functions

Message ID 1362405624-12084-1-git-send-email-johan.mossberg@stericsson.com
State New
Headers show

Commit Message

Johan Mossberg March 4, 2013, 2 p.m. UTC
ion_client_create and ion_heap_create assumes the caller will keep the
name string valid forever. In my opinion this is not the expected
behavior, it also makes it difficult to have dynamically created names.

Signed-off-by: Johan Mossberg <johan.mossberg@stericsson.com>
---
 drivers/gpu/ion/ion.c      |   11 +++++++----
 drivers/gpu/ion/ion_heap.c |    3 ++-
 drivers/gpu/ion/ion_priv.h |    4 +++-
 3 files changed, 12 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
index 8fd61b3..b0ad01b 100644
--- a/drivers/gpu/ion/ion.c
+++ b/drivers/gpu/ion/ion.c
@@ -57,6 +57,8 @@  struct ion_device {
 	struct dentry *debug_root;
 };
 
+#define CLIENT_NAME_LEN 16
+
 /**
  * struct ion_client - a process/hw block local address space
  * @node:		node in the tree of all clients
@@ -75,7 +77,7 @@  struct ion_client {
 	struct ion_device *dev;
 	struct rb_root handles;
 	struct mutex lock;
-	const char *name;
+	char name[CLIENT_NAME_LEN];
 	struct task_struct *task;
 	pid_t pid;
 	struct dentry *debug_root;
@@ -598,14 +600,14 @@  static int ion_debug_client_show(struct seq_file *s, void *unused)
 			names[id] = handle->buffer->heap->name;
 		sizes[id] += handle->buffer->size;
 	}
-	mutex_unlock(&client->lock);
-
 	seq_printf(s, "%16.16s: %16.16s\n", "heap_name", "size_in_bytes");
 	for (i = 0; i < ION_NUM_HEAP_IDS; i++) {
 		if (!names[i])
 			continue;
 		seq_printf(s, "%16.16s: %16u\n", names[i], sizes[i]);
 	}
+	mutex_unlock(&client->lock);
+
 	return 0;
 }
 
@@ -655,7 +657,8 @@  struct ion_client *ion_client_create(struct ion_device *dev,
 	client->dev = dev;
 	client->handles = RB_ROOT;
 	mutex_init(&client->lock);
-	client->name = name;
+	strncpy(client->name, name, CLIENT_NAME_LEN);
+	client->name[CLIENT_NAME_LEN - 1] = '\0';
 	client->task = task;
 	client->pid = pid;
 
diff --git a/drivers/gpu/ion/ion_heap.c b/drivers/gpu/ion/ion_heap.c
index 225ef94..96dd70b 100644
--- a/drivers/gpu/ion/ion_heap.c
+++ b/drivers/gpu/ion/ion_heap.c
@@ -160,7 +160,8 @@  struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data)
 		return ERR_PTR(-EINVAL);
 	}
 
-	heap->name = heap_data->name;
+	strncpy(heap->name, heap_data->name, HEAP_NAME_LEN);
+	heap->name[HEAP_NAME_LEN - 1] = '\0';
 	heap->id = heap_data->id;
 	return heap;
 }
diff --git a/drivers/gpu/ion/ion_priv.h b/drivers/gpu/ion/ion_priv.h
index c116921..3296ba4 100644
--- a/drivers/gpu/ion/ion_priv.h
+++ b/drivers/gpu/ion/ion_priv.h
@@ -107,6 +107,8 @@  struct ion_heap_ops {
 			 struct vm_area_struct *vma);
 };
 
+#define HEAP_NAME_LEN 16
+
 /**
  * struct ion_heap - represents a heap in the system
  * @node:		rb node to put the heap on the device's tree of heaps
@@ -131,7 +133,7 @@  struct ion_heap {
 	enum ion_heap_type type;
 	struct ion_heap_ops *ops;
 	unsigned int id;
-	const char *name;
+	char name[HEAP_NAME_LEN];
 	int (*debug_show)(struct ion_heap *heap, struct seq_file *, void *);
 };