Commit 46d4e747 authored by Markus Elfring's avatar Markus Elfring Committed by Paul Mackerras

KVM: PPC: e500: Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection

The kfree() function was called in two cases by the
kvm_vcpu_ioctl_config_tlb() function during error handling
even if the passed data structure element contained a null pointer.

* Split a condition check for memory allocation failures.

* Adjust jump targets according to the Linux coding style convention.
Signed-off-by: default avatarMarkus Elfring <elfring@users.sourceforge.net>
Signed-off-by: default avatarPaul Mackerras <paulus@ozlabs.org>
parent f3c0ce86
...@@ -785,35 +785,39 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, ...@@ -785,35 +785,39 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
ret = get_user_pages_fast(cfg->array, num_pages, 1, pages); ret = get_user_pages_fast(cfg->array, num_pages, 1, pages);
if (ret < 0) if (ret < 0)
goto err_pages; goto free_pages;
if (ret != num_pages) { if (ret != num_pages) {
num_pages = ret; num_pages = ret;
ret = -EFAULT; ret = -EFAULT;
goto err_put_page; goto put_pages;
} }
virt = vmap(pages, num_pages, VM_MAP, PAGE_KERNEL); virt = vmap(pages, num_pages, VM_MAP, PAGE_KERNEL);
if (!virt) { if (!virt) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_put_page; goto put_pages;
} }
privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0], privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0],
GFP_KERNEL); GFP_KERNEL);
if (!privs[0]) {
ret = -ENOMEM;
goto put_pages;
}
privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1], privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1],
GFP_KERNEL); GFP_KERNEL);
if (!privs[1]) {
if (!privs[0] || !privs[1]) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_privs; goto free_privs_first;
} }
g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1], g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1],
GFP_KERNEL); GFP_KERNEL);
if (!g2h_bitmap) { if (!g2h_bitmap) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_privs; goto free_privs_second;
} }
free_gtlb(vcpu_e500); free_gtlb(vcpu_e500);
...@@ -845,16 +849,14 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, ...@@ -845,16 +849,14 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
kvmppc_recalc_tlb1map_range(vcpu_e500); kvmppc_recalc_tlb1map_range(vcpu_e500);
return 0; return 0;
free_privs_second:
err_privs:
kfree(privs[0]);
kfree(privs[1]); kfree(privs[1]);
free_privs_first:
err_put_page: kfree(privs[0]);
put_pages:
for (i = 0; i < num_pages; i++) for (i = 0; i < num_pages; i++)
put_page(pages[i]); put_page(pages[i]);
free_pages:
err_pages:
kfree(pages); kfree(pages);
return ret; return ret;
} }
......
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