From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965524Ab2KBCoB (ORCPT ); Thu, 1 Nov 2012 22:44:01 -0400 Received: from mga03.intel.com ([143.182.124.21]:51533 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758264Ab2KBCn5 (ORCPT ); Thu, 1 Nov 2012 22:43:57 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.80,696,1344236400"; d="scan'208";a="212521648" Date: Fri, 2 Nov 2012 10:43:54 +0800 From: Fengguang Wu To: Alex Williamson Cc: linux-kernel@vger.kernel.org, Julia Lawall Subject: [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user Message-ID: <20121102024354.GA29600@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Generated by: coccinelle/api/memdup_user.cocci Acked-by: Julia Lawall Reported-by: Fengguang Wu --- 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);