From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751548AbbLUUEK (ORCPT ); Mon, 21 Dec 2015 15:04:10 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:35887 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750914AbbLUUEI (ORCPT ); Mon, 21 Dec 2015 15:04:08 -0500 Date: Mon, 21 Dec 2015 12:04:05 -0800 From: Dmitry Torokhov To: Rahul Pathak Cc: gregkh@linuxfoundation.org, jslaby@suse.com, samuel.thibault@ens-lyon.org, pavel@ucw.cz, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tty: vt: use memdup_user to reuse the code Message-ID: <20151221200405.GA40090@dtor-ws> References: <20151219184533.GA7305@platform-Vostro-3546> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151219184533.GA7305@platform-Vostro-3546> 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 On Sun, Dec 20, 2015 at 12:15:33AM +0530, Rahul Pathak wrote: > Fixing coccicheck warning which recommends to use memdup_user instead > to reimplement its code, using memdup_user simplifies the code > > ./drivers/tty/vt/keyboard.c:1709:9-16: WARNING opportunity for memdup_user > ./drivers/tty/vt/keyboard.c:1752:9-16: WARNING opportunity for memdup_user > > Signed-off-by: Rahul Pathak Acked-by: Dmitry Torokhov (assuming Greg will pick it up, otherwise I can take it through my tree). Thanks. > --- > drivers/tty/vt/keyboard.c | 28 ++++++++-------------------- > 1 file changed, 8 insertions(+), 20 deletions(-) > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index 6f0336f..ec05360 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -1706,16 +1706,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) > return -EINVAL; > > if (ct) { > - dia = kmalloc(sizeof(struct kbdiacr) * ct, > - GFP_KERNEL); > - if (!dia) > - return -ENOMEM; > - > - if (copy_from_user(dia, a->kbdiacr, > - sizeof(struct kbdiacr) * ct)) { > - kfree(dia); > - return -EFAULT; > - } > + dia = memdup_user(a->kbdiacr, > + sizeof(struct kbdiacr) * ct); > + if (IS_ERR(dia)) > + return PTR_ERR(dia); > } > > spin_lock_irqsave(&kbd_event_lock, flags); > @@ -1749,16 +1743,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) > return -EINVAL; > > if (ct) { > - buf = kmalloc(ct * sizeof(struct kbdiacruc), > - GFP_KERNEL); > - if (buf == NULL) > - return -ENOMEM; > - > - if (copy_from_user(buf, a->kbdiacruc, > - ct * sizeof(struct kbdiacruc))) { > - kfree(buf); > - return -EFAULT; > - } > + buf = memdup_user(a->kbdiacruc, > + sizeof(struct kbdiacruc) * ct); > + if (IS_ERR(buf)) > + return PTR_ERR(buf); > } > spin_lock_irqsave(&kbd_event_lock, flags); > if (ct) > -- > 2.1.4 > -- Dmitry