From patchwork Sat Sep 24 11:08:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9349157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E37EB6077A for ; Sat, 24 Sep 2016 11:09:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D38FC29F07 for ; Sat, 24 Sep 2016 11:09:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C85F429F0B; Sat, 24 Sep 2016 11:09:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63CF929F07 for ; Sat, 24 Sep 2016 11:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752479AbcIXLJN (ORCPT ); Sat, 24 Sep 2016 07:09:13 -0400 Received: from mout.web.de ([212.227.17.12]:62648 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752171AbcIXLJM (ORCPT ); Sat, 24 Sep 2016 07:09:12 -0400 Received: from [192.168.1.2] ([78.53.181.42]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0MHY5w-1boqDl0rHQ-003OPj; Sat, 24 Sep 2016 13:08:57 +0200 Subject: [PATCH 1/2] Input-evdev: Use kmalloc_array() in evdev_handle_get_val() To: linux-input@vger.kernel.org, Dmitry Torokhov , Henrik Rydberg References: <566ABCD9.1060404@users.sourceforge.net> <92cc52f5-c5e1-cafe-76f2-04e4ed997735@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <2a1f52e8-a502-1d4b-d9c9-e806cc6f246e@users.sourceforge.net> Date: Sat, 24 Sep 2016 13:08:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <92cc52f5-c5e1-cafe-76f2-04e4ed997735@users.sourceforge.net> X-Provags-ID: V03:K0:O6FFuVN2fxQTnlZ4G0GQWpsKzK8Y3d4GVKLCRcXU1TxYt/n9wMj KCJLBTL/uFoZoWLLK8IJ95rEDVRx1QX5uulPxWAy8Jq+w3Y/XVd/RjyliafVjn14Q8rf/H8 XmfXYwmYH7LRdjDMasjjk+YM9kt4Vqgc5q+NrMtaj6L1Mizcy0ohIZTUTkMgomb+w7O7DTG U7P+IxkLCwxatb+Kb/+uA== X-UI-Out-Filterresults: notjunk:1; V01:K0:BCSfA6AqKw4=:LvrXq7XS8s2482J+aw4S0F gI0t4c0DK2Y1ZhDufb/LyksaPdR+8vGdWCYfwyZ7xRgnbXxYG6kEMWD7IVpbUBxaWIlWkoH2F IHm91Kh1/KX5apPGUs42XU6fyabbU05Xx8AlZcf/x2jBiX+G0z6XT6xYkgaUjKl+Y2KPTZQCJ b6i1HcwRihEoqCyQk5dx6SfKoytV0d/yA+kQVcSG8SNZ8f0X9b988MMrY6NRha/fNwznXFFIF zNs2WnGBtLldPAS5qhMagVKdkslRdqPe5wa5SeVv3U7wJdJhSfutUFcOn62FZHhlvM6lIHDwM f4fLbgDmXfrbA/CQDoiJEJewT0YJtQgR4cHHZcpkE38KGVzX8vp2fSHmXRQVTpDoHcGjdbx5+ 3+0rXuTMmGyP6n3YdxZfnTeCQvqTsf6mZIquewgRtdMxmImNV3lbrY1jK3WXx4ulOTzjCAr5X xzU2fPpM8iTJObVhslmRW1t7W5NyaIxDrJLDJBYbD5TYDRuyrZvI9jGs85UVcROmYqZH+3ug+ ni69M5NNAfmFl/v0lmPmcRlPAMW8mYY3OfsiyOtprx/IX6PYjFc8pXiFw+lkD+gUTSexAdfYN h7DhHQt/r5w6Mr+fNUE3o92ZvhBPU3rjrCApBbxSy3iUCc/AvBnoKAteeDkw3LbWfqFj7/PDt X/agydFLoTz7Rq9Raxm5Gk+Td1kVx0fmIrvUAcYCBy7f5/KeYNyitPN9as2nrd/AtH80OEh93 F1mau0P0a1w2VixJT3Le4QbZ0t1si9Moj+VViSfXiLMSwSJlRBE7f3PGEmRsY0OK8TetqxOW3 izRzLWJ Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 24 Sep 2016 12:42:45 +0200 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. * Delete the local variable "len" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/input/evdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index e9ae3d5..83fcfd6 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -919,18 +919,14 @@ static int evdev_handle_get_val(struct evdev_client *client, { int ret; unsigned long *mem; - size_t len; - len = BITS_TO_LONGS(maxbit) * sizeof(unsigned long); - mem = kmalloc(len, GFP_KERNEL); + mem = kmalloc_array(BITS_TO_LONGS(maxbit), sizeof(*mem), GFP_KERNEL); if (!mem) return -ENOMEM; spin_lock_irq(&dev->event_lock); spin_lock(&client->buffer_lock); - - memcpy(mem, bits, len); - + memcpy(mem, bits, sizeof(*mem) * BITS_TO_LONGS(maxbit)); spin_unlock(&dev->event_lock); __evdev_flush_queue(client, type);