kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] KVM: Use kmemdup() instead of kmalloc/memcpy
@ 2011-11-27 12:43 Sasha Levin
  2011-11-27 12:43 ` [PATCH v2 2/2] KVM: Use memdup_user instead of kmalloc/copy_from_user Sasha Levin
  2011-12-04 16:57 ` [PATCH v2 1/2] KVM: Use kmemdup() instead of kmalloc/memcpy Avi Kivity
  0 siblings, 2 replies; 3+ messages in thread
From: Sasha Levin @ 2011-11-27 12:43 UTC (permalink / raw)
  To: kvm; +Cc: Sasha Levin, Avi Kivity, Marcelo Tosatti

Switch to kmemdup() in two places to shorten the code and avoid possible bugs.

Cc: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 arch/x86/kvm/x86.c  |    5 +++--
 virt/kvm/kvm_main.c |    7 +++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1985ea1..3edaf95 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3540,13 +3540,14 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
 		memset(dirty_bitmap, 0, n);
 
 		r = -ENOMEM;
-		slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
+		slots = kmemdup(kvm->memslots, sizeof(*kvm->memslots), GFP_KERNEL);
 		if (!slots)
 			goto out;
-		memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
+
 		memslot = &slots->memslots[log->slot];
 		memslot->dirty_bitmap = dirty_bitmap;
 		memslot->nr_dirty_pages = 0;
+
 		slots->generation++;
 
 		old_slots = kvm->memslots;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index af5c988..d05fef8 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2540,13 +2540,12 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
 	int i, r;
 	struct kvm_io_bus *new_bus, *bus;
 
-	new_bus = kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL);
+	bus = kvm->buses[bus_idx];
+
+	new_bus = kmemdup(bus, sizeof(*bus), GFP_KERNEL);
 	if (!new_bus)
 		return -ENOMEM;
 
-	bus = kvm->buses[bus_idx];
-	memcpy(new_bus, bus, sizeof(struct kvm_io_bus));
-
 	r = -ENOENT;
 	for (i = 0; i < new_bus->dev_count; i++)
 		if (new_bus->range[i].dev == dev) {
-- 
1.7.8.rc3


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

end of thread, other threads:[~2011-12-04 16:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-27 12:43 [PATCH v2 1/2] KVM: Use kmemdup() instead of kmalloc/memcpy Sasha Levin
2011-11-27 12:43 ` [PATCH v2 2/2] KVM: Use memdup_user instead of kmalloc/copy_from_user Sasha Levin
2011-12-04 16:57 ` [PATCH v2 1/2] KVM: Use kmemdup() instead of kmalloc/memcpy Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).