public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Fengguang Wu <fengguang.wu@intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: linux-kernel@vger.kernel.org, Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user
Date: Fri, 2 Nov 2012 10:43:54 +0800	[thread overview]
Message-ID: <20121102024354.GA29600@localhost> (raw)

Generated by: coccinelle/api/memdup_user.cocci

Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
---

 drivers/vfio/pci/vfio_pci.c |   13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

--- linux.orig/drivers/vfio/pci/vfio_pci.c	2012-10-23 18:21:57.118168335 +0800
+++ linux/drivers/vfio/pci/vfio_pci.c	2012-11-02 10:39:36.101317628 +0800
@@ -327,15 +327,10 @@ static long vfio_pci_ioctl(void *device_
 			    hdr.count > vfio_pci_get_irq_count(vdev, hdr.index))
 				return -EINVAL;
 
-			data = kmalloc(hdr.count * size, GFP_KERNEL);
-			if (!data)
-				return -ENOMEM;
-
-			if (copy_from_user(data, (void __user *)(arg + minsz),
-					   hdr.count * size)) {
-				kfree(data);
-				return -EFAULT;
-			}
+			data = memdup_user((void __user *)(arg + minsz),
+					   hdr.count * size);
+			if (IS_ERR(data))
+				return PTR_ERR(data);
 		}
 
 		mutex_lock(&vdev->igate);

             reply	other threads:[~2012-11-02  2:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-02  2:43 Fengguang Wu [this message]
2012-11-09 13:06 ` [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121102024354.GA29600@localhost \
    --to=fengguang.wu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox