Commit 6da64fdb authored by Thomas Meyer's avatar Thomas Meyer Committed by Avi Kivity

KVM: Use kmemdup rather than duplicating its implementation

 Use kmemdup rather than duplicating its implementation

 The semantic patch that makes this change is available
 in scripts/coccinelle/api/memdup.cocci.

 More information about semantic patching is available at
 http://coccinelle.lip6.fr/Signed-off-by: default avatarThomas Meyer <thomas@m3y3r.de>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent fb920458
...@@ -775,10 +775,10 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -775,10 +775,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
if (!npages) { if (!npages) {
r = -ENOMEM; r = -ENOMEM;
slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
GFP_KERNEL);
if (!slots) if (!slots)
goto out_free; goto out_free;
memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
if (mem->slot >= slots->nmemslots) if (mem->slot >= slots->nmemslots)
slots->nmemslots = mem->slot + 1; slots->nmemslots = mem->slot + 1;
slots->generation++; slots->generation++;
...@@ -810,10 +810,10 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -810,10 +810,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
} }
r = -ENOMEM; r = -ENOMEM;
slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
GFP_KERNEL);
if (!slots) if (!slots)
goto out_free; goto out_free;
memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
if (mem->slot >= slots->nmemslots) if (mem->slot >= slots->nmemslots)
slots->nmemslots = mem->slot + 1; slots->nmemslots = mem->slot + 1;
slots->generation++; slots->generation++;
...@@ -2520,10 +2520,9 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, ...@@ -2520,10 +2520,9 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
if (bus->dev_count > NR_IOBUS_DEVS-1) if (bus->dev_count > NR_IOBUS_DEVS-1)
return -ENOSPC; return -ENOSPC;
new_bus = kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL); new_bus = kmemdup(bus, sizeof(struct kvm_io_bus), GFP_KERNEL);
if (!new_bus) if (!new_bus)
return -ENOMEM; return -ENOMEM;
memcpy(new_bus, bus, sizeof(struct kvm_io_bus));
kvm_io_bus_insert_dev(new_bus, dev, addr, len); kvm_io_bus_insert_dev(new_bus, dev, addr, len);
rcu_assign_pointer(kvm->buses[bus_idx], new_bus); rcu_assign_pointer(kvm->buses[bus_idx], new_bus);
synchronize_srcu_expedited(&kvm->srcu); synchronize_srcu_expedited(&kvm->srcu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment