From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752475AbdEFRlG (ORCPT ); Sat, 6 May 2017 13:41:06 -0400 Received: from canardo.mork.no ([148.122.252.1]:37265 "EHLO canardo.mork.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751116AbdEFRlA (ORCPT ); Sat, 6 May 2017 13:41:00 -0400 From: =?utf-8?Q?Bj=C3=B8rn_Mork?= To: Geliang Tang Cc: Greg Kroah-Hartman , Oliver Neukum , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: cdc-wdm: use memdup_user Organization: m References: Date: Sat, 06 May 2017 19:40:42 +0200 In-Reply-To: (Geliang Tang's message of "Sat, 6 May 2017 23:42:18 +0800") Message-ID: <87vapddgth.fsf@miraculix.mork.no> User-Agent: Gnus/5.130015 (Ma Gnus v0.15) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id v46HfXuZ007278 Geliang Tang writes: > Use memdup_user() helper instead of open-coding to simplify the code. > > Signed-off-by: Geliang Tang > --- > drivers/usb/class/cdc-wdm.c | 15 +++------------ > 1 file changed, 3 insertions(+), 12 deletions(-) > > diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c > index 08669fe..0e4f18c 100644 > --- a/drivers/usb/class/cdc-wdm.c > +++ b/drivers/usb/class/cdc-wdm.c > @@ -361,17 +361,9 @@ static ssize_t wdm_write > if (we < 0) > return usb_translate_errors(we); > > - buf = kmalloc(count, GFP_KERNEL); > - if (!buf) { > - rv = -ENOMEM; > - goto outnl; > - } > - > - r = copy_from_user(buf, buffer, count); > - if (r > 0) { > - rv = -EFAULT; > - goto out_free_mem; > - } > + buf = memdup_user(buffer, count); > + if (IS_ERR(buf)) > + return PTR_ERR(buf); > > /* concurrent writes and disconnect */ > r = mutex_lock_interruptible(&desc->wlock); > @@ -441,7 +433,6 @@ static ssize_t wdm_write > > usb_autopm_put_interface(desc->intf); > mutex_unlock(&desc->wlock); > -outnl: > return rv < 0 ? rv : count; > > out_free_mem_pm: Nice! Please check this, but I believe you can simplify that last return as well. There is no way to end up there with rv < 0 after you've removed the label. So return count; should do. Bjørn