Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1599201

[PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset

From Daeseok Youn <daeseok.youn@gmail.com>
Newsgroups linux.kernel
Subject [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset
Date 2017-03-13 12:00 +0100
Message-ID <tkvRL-7Mz-1@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


If the atomisp_kernel_zalloc() has "true" as a second parameter, it
tries to allocate zeroing memory from kmalloc(vmalloc) and memset.
But using kzalloc is rather than kmalloc followed by memset with 0.
(vzalloc is for same reason with kzalloc)

And also atomisp_kernel_malloc() can be used with
atomisp_kernel_zalloc(<size>, false);

Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
---
I think kvmalloc() or kvzalloc() can be used to allocate memory if there is
no reason to use vmalloc() when the requested bytes is over PAGE_SIZE.

 .../media/atomisp/pci/atomisp2/atomisp_cmd.c       | 25 ++++++++++++----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c
index d9a5c24..44b2244 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c
@@ -86,32 +86,35 @@
 };
 
 /*
- * atomisp_kernel_malloc: chooses whether kmalloc() or vmalloc() is preferable.
+ * atomisp_kernel_malloc:
+ * allocating memory from atomisp_kernel_zalloc() without zeroing memory.
  *
  * It is also a wrap functions to pass into css framework.
  */
 void *atomisp_kernel_malloc(size_t bytes)
 {
-	/* vmalloc() is preferable if allocating more than 1 page */
-	if (bytes > PAGE_SIZE)
-		return vmalloc(bytes);
-
-	return kmalloc(bytes, GFP_KERNEL);
+	return atomisp_kernel_zalloc(bytes, false);
 }
 
 /*
- * atomisp_kernel_zalloc: chooses whether set 0 to the allocated memory.
+ * atomisp_kernel_zalloc: chooses whether set 0 to the allocated memory
+ * with k{z,m}alloc or v{z,m}alloc
  *
  * It is also a wrap functions to pass into css framework.
  */
 void *atomisp_kernel_zalloc(size_t bytes, bool zero_mem)
 {
-	void *ptr = atomisp_kernel_malloc(bytes);
+	/* vmalloc() is preferable if allocating more than 1 page */
+	if (bytes > PAGE_SIZE) {
+		if (zero_mem)
+			return vzalloc(bytes);
+		return vmalloc(bytes);
+	}
 
-	if (ptr && zero_mem)
-		memset(ptr, 0, bytes);
+	if (zero_mem)
+		return kzalloc(bytes, GFP_KERNEL);
 
-	return ptr;
+	return kmalloc(bytes, GFP_KERNEL);
 }
 
 /*
-- 
1.9.1

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and  memset Daeseok Youn <daeseok.youn@gmail.com> - 2017-03-13 12:00 +0100
  Re: [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc  and memset Dan Carpenter <dan.carpenter@oracle.com> - 2017-03-13 13:00 +0100
    Re: [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset DaeSeok Youn <daeseok.youn@gmail.com> - 2017-03-13 15:10 +0100
      Re: [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset DaeSeok Youn <daeseok.youn@gmail.com> - 2017-03-13 16:50 +0100
  Re: [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc  and memset Alan Cox <alan@linux.intel.com> - 2017-03-13 19:00 +0100
    Re: [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset DaeSeok Youn <daeseok.youn@gmail.com> - 2017-03-14 02:20 +0100

csiph-web