Skip to contentSkip to conversation

ion:change ion_cma_allocate return error value

RFC In review Wang, Yalin 3 participants 4 messages Jan 27, 2015 – Jan 29, 2015 Staging

lore
Share & tools
lore
#0 lore raw

RFC 1/1 ion:change ion_cma_allocate return error value

This patch change the error return value from -1 to -ENOMEM, so that userspace can get the correct errno, otherwise,
-1 will be -EPERM, userspace will print permission deny for allocation failure.

---
 drivers/staging/android/ion/ion_cma_heap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/android/ion/ion_cma_heap.c +2 -4
index f4211f1..55bcaec2 100644
@@ -24,8 +24,6 @@
 #include "ion.h"
 #include "ion_priv.h"
 
-#define ION_CMA_ALLOCATE_FAILED -1
-
 struct ion_cma_heap {
 	struct ion_heap heap;
 	struct device *dev;
@@ -59,7 +57,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
 
 	info = kzalloc(sizeof(struct ion_cma_buffer_info), GFP_KERNEL);
 	if (!info)
-		return ION_CMA_ALLOCATE_FAILED;
+		return -ENOMEM;
 
 	info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
 						GFP_HIGHUSER | __GFP_ZERO);
@@ -87,7 +85,7 @@ free_mem:
 	dma_free_coherent(dev, len, info->cpu_addr, info->handle);
 err:
 	kfree(info);
-	return ION_CMA_ALLOCATE_FAILED;
+	return -ENOMEM;
 }
 
 static void ion_cma_free(struct ion_buffer *buffer)
Signature · 1 line
2.2.2
#3 lore raw
In reply to '[email protected]'
Quoted 15 lines

-----Original Message-----
From: '[email protected]' [mailto:[email protected]]
Sent: Thursday, January 29, 2015 2:45 AM
To: Wang, Yalin
Cc: '[email protected]'; '[email protected]'; '[email protected]'; '[email protected]'; 'linux- [email protected]'; Gao, Neil
Subject: Re: [RFC] ion:change ion_cma_allocate return error value

Quoted 5 lines · Yalin

This patch change the error return value from -1 to -ENOMEM, so that userspace can get the correct errno, otherwise,
-1 will be -EPERM, userspace will print permission deny for allocation failure.

Quoted 8 lines
Quoted 4 lines
---
 drivers/staging/android/ion/ion_cma_heap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Don't you also need to now change userspace code to properly handle these errors?

No, because userspace use strerror() to print errno, It will print correct error string depending on kernel return Errno.

#2 lore raw
In reply to Wang, Yalin
Quoted 9 lines · Yalin

This patch change the error return value from -1 to -ENOMEM, so that userspace can get the correct errno, otherwise,
-1 will be -EPERM, userspace will print permission deny for allocation failure.

---
 drivers/staging/android/ion/ion_cma_heap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Don't you also need to now change userspace code to properly handle these errors?

greg k-h