diff options
author | Avi Kivity <avi@redhat.com> | 2010-06-20 08:54:43 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-08-01 03:46:57 -0400 |
commit | d1ac91d8a2f00dc6a3954f7e8971339b0893edc4 (patch) | |
tree | 4748e076b42e4aacdd4ad6cc9d5741d384bf826b /arch/x86/kvm/x86.c | |
parent | a1a005f36e0defea7c5490772c318c6af2261d31 (diff) |
KVM: Consolidate load/save temporary buffer allocation and freeing
Instead of three temporary variables and three free calls, have one temporary
variable (with four names) and one free call.
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d918cb15e5b5..8e60b6c9c0b0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -2436,25 +2436,29 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2436 | struct kvm_vcpu *vcpu = filp->private_data; | 2436 | struct kvm_vcpu *vcpu = filp->private_data; |
2437 | void __user *argp = (void __user *)arg; | 2437 | void __user *argp = (void __user *)arg; |
2438 | int r; | 2438 | int r; |
2439 | struct kvm_lapic_state *lapic = NULL; | 2439 | union { |
2440 | struct kvm_xsave *xsave = NULL; | 2440 | struct kvm_lapic_state *lapic; |
2441 | struct kvm_xcrs *xcrs = NULL; | 2441 | struct kvm_xsave *xsave; |
2442 | struct kvm_xcrs *xcrs; | ||
2443 | void *buffer; | ||
2444 | } u; | ||
2442 | 2445 | ||
2446 | u.buffer = NULL; | ||
2443 | switch (ioctl) { | 2447 | switch (ioctl) { |
2444 | case KVM_GET_LAPIC: { | 2448 | case KVM_GET_LAPIC: { |
2445 | r = -EINVAL; | 2449 | r = -EINVAL; |
2446 | if (!vcpu->arch.apic) | 2450 | if (!vcpu->arch.apic) |
2447 | goto out; | 2451 | goto out; |
2448 | lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); | 2452 | u.lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); |
2449 | 2453 | ||
2450 | r = -ENOMEM; | 2454 | r = -ENOMEM; |
2451 | if (!lapic) | 2455 | if (!u.lapic) |
2452 | goto out; | 2456 | goto out; |
2453 | r = kvm_vcpu_ioctl_get_lapic(vcpu, lapic); | 2457 | r = kvm_vcpu_ioctl_get_lapic(vcpu, u.lapic); |
2454 | if (r) | 2458 | if (r) |
2455 | goto out; | 2459 | goto out; |
2456 | r = -EFAULT; | 2460 | r = -EFAULT; |
2457 | if (copy_to_user(argp, lapic, sizeof(struct kvm_lapic_state))) | 2461 | if (copy_to_user(argp, u.lapic, sizeof(struct kvm_lapic_state))) |
2458 | goto out; | 2462 | goto out; |
2459 | r = 0; | 2463 | r = 0; |
2460 | break; | 2464 | break; |
@@ -2463,14 +2467,14 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2463 | r = -EINVAL; | 2467 | r = -EINVAL; |
2464 | if (!vcpu->arch.apic) | 2468 | if (!vcpu->arch.apic) |
2465 | goto out; | 2469 | goto out; |
2466 | lapic = kmalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); | 2470 | u.lapic = kmalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); |
2467 | r = -ENOMEM; | 2471 | r = -ENOMEM; |
2468 | if (!lapic) | 2472 | if (!u.lapic) |
2469 | goto out; | 2473 | goto out; |
2470 | r = -EFAULT; | 2474 | r = -EFAULT; |
2471 | if (copy_from_user(lapic, argp, sizeof(struct kvm_lapic_state))) | 2475 | if (copy_from_user(u.lapic, argp, sizeof(struct kvm_lapic_state))) |
2472 | goto out; | 2476 | goto out; |
2473 | r = kvm_vcpu_ioctl_set_lapic(vcpu, lapic); | 2477 | r = kvm_vcpu_ioctl_set_lapic(vcpu, u.lapic); |
2474 | if (r) | 2478 | if (r) |
2475 | goto out; | 2479 | goto out; |
2476 | r = 0; | 2480 | r = 0; |
@@ -2634,68 +2638,66 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2634 | break; | 2638 | break; |
2635 | } | 2639 | } |
2636 | case KVM_GET_XSAVE: { | 2640 | case KVM_GET_XSAVE: { |
2637 | xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL); | 2641 | u.xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL); |
2638 | r = -ENOMEM; | 2642 | r = -ENOMEM; |
2639 | if (!xsave) | 2643 | if (!u.xsave) |
2640 | break; | 2644 | break; |
2641 | 2645 | ||
2642 | kvm_vcpu_ioctl_x86_get_xsave(vcpu, xsave); | 2646 | kvm_vcpu_ioctl_x86_get_xsave(vcpu, u.xsave); |
2643 | 2647 | ||
2644 | r = -EFAULT; | 2648 | r = -EFAULT; |
2645 | if (copy_to_user(argp, xsave, sizeof(struct kvm_xsave))) | 2649 | if (copy_to_user(argp, u.xsave, sizeof(struct kvm_xsave))) |
2646 | break; | 2650 | break; |
2647 | r = 0; | 2651 | r = 0; |
2648 | break; | 2652 | break; |
2649 | } | 2653 | } |
2650 | case KVM_SET_XSAVE: { | 2654 | case KVM_SET_XSAVE: { |
2651 | xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL); | 2655 | u.xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL); |
2652 | r = -ENOMEM; | 2656 | r = -ENOMEM; |
2653 | if (!xsave) | 2657 | if (!u.xsave) |
2654 | break; | 2658 | break; |
2655 | 2659 | ||
2656 | r = -EFAULT; | 2660 | r = -EFAULT; |
2657 | if (copy_from_user(xsave, argp, sizeof(struct kvm_xsave))) | 2661 | if (copy_from_user(u.xsave, argp, sizeof(struct kvm_xsave))) |
2658 | break; | 2662 | break; |
2659 | 2663 | ||
2660 | r = kvm_vcpu_ioctl_x86_set_xsave(vcpu, xsave); | 2664 | r = kvm_vcpu_ioctl_x86_set_xsave(vcpu, u.xsave); |
2661 | break; | 2665 | break; |
2662 | } | 2666 | } |
2663 | case KVM_GET_XCRS: { | 2667 | case KVM_GET_XCRS: { |
2664 | xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL); | 2668 | u.xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL); |
2665 | r = -ENOMEM; | 2669 | r = -ENOMEM; |
2666 | if (!xcrs) | 2670 | if (!u.xcrs) |
2667 | break; | 2671 | break; |
2668 | 2672 | ||
2669 | kvm_vcpu_ioctl_x86_get_xcrs(vcpu, xcrs); | 2673 | kvm_vcpu_ioctl_x86_get_xcrs(vcpu, u.xcrs); |
2670 | 2674 | ||
2671 | r = -EFAULT; | 2675 | r = -EFAULT; |
2672 | if (copy_to_user(argp, xcrs, | 2676 | if (copy_to_user(argp, u.xcrs, |
2673 | sizeof(struct kvm_xcrs))) | 2677 | sizeof(struct kvm_xcrs))) |
2674 | break; | 2678 | break; |
2675 | r = 0; | 2679 | r = 0; |
2676 | break; | 2680 | break; |
2677 | } | 2681 | } |
2678 | case KVM_SET_XCRS: { | 2682 | case KVM_SET_XCRS: { |
2679 | xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL); | 2683 | u.xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL); |
2680 | r = -ENOMEM; | 2684 | r = -ENOMEM; |
2681 | if (!xcrs) | 2685 | if (!u.xcrs) |
2682 | break; | 2686 | break; |
2683 | 2687 | ||
2684 | r = -EFAULT; | 2688 | r = -EFAULT; |
2685 | if (copy_from_user(xcrs, argp, | 2689 | if (copy_from_user(u.xcrs, argp, |
2686 | sizeof(struct kvm_xcrs))) | 2690 | sizeof(struct kvm_xcrs))) |
2687 | break; | 2691 | break; |
2688 | 2692 | ||
2689 | r = kvm_vcpu_ioctl_x86_set_xcrs(vcpu, xcrs); | 2693 | r = kvm_vcpu_ioctl_x86_set_xcrs(vcpu, u.xcrs); |
2690 | break; | 2694 | break; |
2691 | } | 2695 | } |
2692 | default: | 2696 | default: |
2693 | r = -EINVAL; | 2697 | r = -EINVAL; |
2694 | } | 2698 | } |
2695 | out: | 2699 | out: |
2696 | kfree(lapic); | 2700 | kfree(u.buffer); |
2697 | kfree(xsave); | ||
2698 | kfree(xcrs); | ||
2699 | return r; | 2701 | return r; |
2700 | } | 2702 | } |
2701 | 2703 | ||