KVM: s390: Use memdup_user() rather than duplicating code
authorMarkus Elfring <elfring@users.sourceforge.net>
Wed, 24 Aug 2016 18:10:09 +0000 (20:10 +0200)
committerChristian Borntraeger <borntraeger@de.ibm.com>
Thu, 8 Sep 2016 11:40:55 +0000 (13:40 +0200)
* Reuse existing functionality from memdup_user() instead of keeping
  duplicate source code.

  This issue was detected by using the Coccinelle software.

* Return directly if this copy operation failed.

Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Message-Id: <c86f7520-885e-2829-ae9c-b81caa898e84@users.sourceforge.net>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
arch/s390/kvm/guestdbg.c

index 70b71ac1660e811203f58a286d5f0917821c0ecf..d7c6a7f53cedb3b1694589d6644346570b12ea1b 100644 (file)
@@ -216,20 +216,10 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
        else if (dbg->arch.nr_hw_bp > MAX_BP_COUNT)
                return -EINVAL;
 
-       bp_data = kmalloc_array(dbg->arch.nr_hw_bp,
-                               sizeof(*bp_data),
-                               GFP_KERNEL);
-       if (!bp_data) {
-               ret = -ENOMEM;
-               goto error;
-       }
-
-       if (copy_from_user(bp_data,
-                          dbg->arch.hw_bp,
-                          sizeof(*bp_data) * dbg->arch.nr_hw_bp)) {
-               ret = -EFAULT;
-               goto error;
-       }
+       bp_data = memdup_user(dbg->arch.hw_bp,
+                             sizeof(*bp_data) * dbg->arch.nr_hw_bp);
+       if (IS_ERR(bp_data))
+               return PTR_ERR(bp_data);
 
        for (i = 0; i < dbg->arch.nr_hw_bp; i++) {
                switch (bp_data[i].type) {