diff options
author | Sasha Levin <levinsasha928@gmail.com> | 2011-12-04 12:36:28 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-12-27 04:22:20 -0500 |
commit | cdfca7b346e6dbab1ba33260c28ccb8333485a5b (patch) | |
tree | 423d4487ee5604a69943e8daade01fbec1879ef6 | |
parent | 3f745f1e224e05e845a15760a55f3fd323f7a753 (diff) |
KVM: Use kmemdup() instead of kmalloc/memcpy
Switch to kmemdup() in two places to shorten the code and avoid possible bugs.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r-- | arch/x86/kvm/x86.c | 4 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 7 |
2 files changed, 5 insertions, 6 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d55a94f1155a..03042d60a8fc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -3031,10 +3031,10 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, | |||
3031 | memset(dirty_bitmap_head, 0, n); | 3031 | memset(dirty_bitmap_head, 0, n); |
3032 | 3032 | ||
3033 | r = -ENOMEM; | 3033 | r = -ENOMEM; |
3034 | slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); | 3034 | slots = kmemdup(kvm->memslots, sizeof(*kvm->memslots), GFP_KERNEL); |
3035 | if (!slots) | 3035 | if (!slots) |
3036 | goto out; | 3036 | goto out; |
3037 | memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); | 3037 | |
3038 | memslot = id_to_memslot(slots, log->slot); | 3038 | memslot = id_to_memslot(slots, log->slot); |
3039 | memslot->nr_dirty_pages = 0; | 3039 | memslot->nr_dirty_pages = 0; |
3040 | memslot->dirty_bitmap = dirty_bitmap_head; | 3040 | memslot->dirty_bitmap = dirty_bitmap_head; |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e289486edc6d..a6e612fced73 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -2591,13 +2591,12 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, | |||
2591 | int i, r; | 2591 | int i, r; |
2592 | struct kvm_io_bus *new_bus, *bus; | 2592 | struct kvm_io_bus *new_bus, *bus; |
2593 | 2593 | ||
2594 | new_bus = kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL); | 2594 | bus = kvm->buses[bus_idx]; |
2595 | |||
2596 | new_bus = kmemdup(bus, sizeof(*bus), GFP_KERNEL); | ||
2595 | if (!new_bus) | 2597 | if (!new_bus) |
2596 | return -ENOMEM; | 2598 | return -ENOMEM; |
2597 | 2599 | ||
2598 | bus = kvm->buses[bus_idx]; | ||
2599 | memcpy(new_bus, bus, sizeof(struct kvm_io_bus)); | ||
2600 | |||
2601 | r = -ENOENT; | 2600 | r = -ENOENT; |
2602 | for (i = 0; i < new_bus->dev_count; i++) | 2601 | for (i = 0; i < new_bus->dev_count; i++) |
2603 | if (new_bus->range[i].dev == dev) { | 2602 | if (new_bus->range[i].dev == dev) { |