From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753204Ab2KINGm (ORCPT ); Fri, 9 Nov 2012 08:06:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61500 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752293Ab2KINGk (ORCPT ); Fri, 9 Nov 2012 08:06:40 -0500 Message-ID: <1352466389.8247.79.camel@ul30vt.home> Subject: Re: [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user From: Alex Williamson To: Fengguang Wu Cc: linux-kernel@vger.kernel.org, Julia Lawall Date: Fri, 09 Nov 2012 14:06:29 +0100 In-Reply-To: <20121102024354.GA29600@localhost> References: <20121102024354.GA29600@localhost> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2012-11-02 at 10:43 +0800, Fengguang Wu wrote: > 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); Thanks for the patch. Looks reasonable to me. I'll add it to my next tree for 3.8. Thanks, Alex