From patchwork Fri Oct 2 13:40:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 7316271 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 215D99F302 for ; Fri, 2 Oct 2015 13:46:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A41020515 for ; Fri, 2 Oct 2015 13:46:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58EA8203B1 for ; Fri, 2 Oct 2015 13:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753589AbbJBNkt (ORCPT ); Fri, 2 Oct 2015 09:40:49 -0400 Received: from lists.s-osg.org ([54.187.51.154]:46942 "EHLO lists.s-osg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753574AbbJBNks (ORCPT ); Fri, 2 Oct 2015 09:40:48 -0400 Received: from localhost.localdomain (148.103.23.95.dynamic.jazztel.es [95.23.103.148]) by lists.s-osg.org (Postfix) with ESMTPSA id 5D522462EB; Fri, 2 Oct 2015 06:40:45 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Javier Martinez Canillas , Dmitry Torokhov , linux-input@vger.kernel.org Subject: [PATCH 01/18] Input: joydev - use memdup_user() to duplicate memory from user-space Date: Fri, 2 Oct 2015 15:40:12 +0200 Message-Id: <1443793229-22363-2-git-send-email-javier@osg.samsung.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443793229-22363-1-git-send-email-javier@osg.samsung.com> References: <1443793229-22363-1-git-send-email-javier@osg.samsung.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The memdup_user() helper function can be used to duplicate a memory region from user-space to kernel-space. There is no need to open code the same logic using kmalloc() and copy_from_user() instead. This was found with make coccicheck that reported the following warning: drivers/input/joydev.c:447:10-17: WARNING opportunity for memdup_user drivers/input/joydev.c:483:10-17: WARNING opportunity for memdup_user Signed-off-by: Javier Martinez Canillas --- drivers/input/joydev.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index 6cb5a3e5f9a1..e3dcd4abae18 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -444,12 +444,9 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev, len = min(len, sizeof(joydev->abspam)); /* Validate the map. */ - abspam = kmalloc(len, GFP_KERNEL); - if (!abspam) - return -ENOMEM; - - if (copy_from_user(abspam, argp, len)) { - retval = -EFAULT; + abspam = memdup_user(argp, len); + if (IS_ERR(abspam)) { + retval = PTR_ERR(abspam); goto out; } @@ -480,12 +477,9 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev, len = min(len, sizeof(joydev->keypam)); /* Validate the map. */ - keypam = kmalloc(len, GFP_KERNEL); - if (!keypam) - return -ENOMEM; - - if (copy_from_user(keypam, argp, len)) { - retval = -EFAULT; + keypam = memdup_user(argp, len); + if (IS_ERR(keypam)) { + retval = PTR_ERR(keypam); goto out; }