All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daeseok Youn <daeseok.youn@gmail.com>
To: mchehab@kernel.org
Cc: gregkh@linuxfoundation.org, alan@linux.intel.com,
	daeseok.youn@gmail.com, linux-media@vger.kernel.org,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset
Date: Mon, 13 Mar 2017 19:54:21 +0900	[thread overview]
Message-ID: <20170313105421.GA32342@SEL-JYOUN-D1> (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

WARNING: multiple messages have this Message-ID (diff)
From: Daeseok Youn <daeseok.youn@gmail.com>
To: mchehab@kernel.org
Cc: gregkh@linuxfoundation.org, alan@linux.intel.com,
	daeseok.youn@gmail.com, linux-media@vger.kernel.org,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset
Date: Mon, 13 Mar 2017 10:54:21 +0000	[thread overview]
Message-ID: <20170313105421.GA32342@SEL-JYOUN-D1> (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


             reply	other threads:[~2017-03-13 10:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 10:54 Daeseok Youn [this message]
2017-03-13 10:54 ` [PATCH] staging: atomisp: use k{v}zalloc instead of k{v}alloc and memset Daeseok Youn
2017-03-13 11:51 ` Dan Carpenter
2017-03-13 11:51   ` Dan Carpenter
2017-03-13 14:07   ` DaeSeok Youn
2017-03-13 14:07     ` DaeSeok Youn
2017-03-13 15:40     ` DaeSeok Youn
2017-03-13 15:40       ` DaeSeok Youn
2017-03-13 17:54 ` Alan Cox
2017-03-14  1:15   ` DaeSeok Youn
2017-03-14  1:15     ` DaeSeok Youn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170313105421.GA32342@SEL-JYOUN-D1 \
    --to=daeseok.youn@gmail.com \
    --cc=alan@linux.intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.