public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM x86: remove memset, use vzalloc and don't assign the same value to a variable twice
@ 2010-10-30 18:28 Jesper Juhl
  2010-11-01  0:49 ` Takuya Yoshikawa
  0 siblings, 1 reply; 6+ messages in thread
From: Jesper Juhl @ 2010-10-30 18:28 UTC (permalink / raw)
  To: kvm
  Cc: Avi Kivity, Avi Kivity, Marcelo Tosatti, Yaniv Kamay, Amit Shah,
	Ben-Ami Yassour, linux-kernel

Hi,

We can improve kvm_vm_ioctl_get_dirty_log() slightly by using vzalloc() 
rather than first allocating and then manually zero the memory with 
memset(). Also, while I was looking at this I noticed that we assign 
-ENOMEM to the 'r' variable twice even though none of the code inbetween 
the two assignments can change 'r', so I removed the second assignment.

Patch has been compile tested only.

Please consider merging and please CC me on all replies as I'm not 
subscribed to the kvm mailing list.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 x86.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2288ad8..29f9c0a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3174,12 +3174,10 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
 		spin_unlock(&kvm->mmu_lock);
 
 		r = -ENOMEM;
-		dirty_bitmap = vmalloc(n);
+		dirty_bitmap = vzalloc(n);
 		if (!dirty_bitmap)
 			goto out;
-		memset(dirty_bitmap, 0, n);
 
-		r = -ENOMEM;
 		slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
 		if (!slots) {
 			vfree(dirty_bitmap);


-- 
Jesper Juhl <jj@chaosbits.net>             http://www.chaosbits.net/
Plain text mails only, please      http://www.expita.com/nomime.html
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-11-03 13:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-30 18:28 [PATCH] KVM x86: remove memset, use vzalloc and don't assign the same value to a variable twice Jesper Juhl
2010-11-01  0:49 ` Takuya Yoshikawa
2010-11-01 18:42   ` Jesper Juhl
2010-11-02  1:49     ` Takuya Yoshikawa
2010-11-02  4:11       ` Jesper Juhl
2010-11-03 12:47         ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox