linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-input@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Henrik Rydberg <rydberg@bitmath.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH 1/2] Input-evdev: Use kmalloc_array() in evdev_handle_get_val()
Date: Sat, 24 Sep 2016 13:08:56 +0200	[thread overview]
Message-ID: <2a1f52e8-a502-1d4b-d9c9-e806cc6f246e@users.sourceforge.net> (raw)
In-Reply-To: <92cc52f5-c5e1-cafe-76f2-04e4ed997735@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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);
-- 
2.10.0


  reply	other threads:[~2016-09-24 11:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-12  9:16 ` [PATCH] uinput: Rename a jump label in uinput_ioctl_handler() SF Markus Elfring
2015-12-12 22:23   ` Dmitry Torokhov
2016-07-02 19:00 ` [PATCH 0/2] Input-at32psif: Fine-tuning for OOM handling in psif_probe() SF Markus Elfring
2016-07-02 19:05   ` [PATCH 1/2] Input-at32psif: Return directly after a failed kzalloc() " SF Markus Elfring
2016-07-02 19:07   ` [PATCH 2/2] Input-at32psif: Remove OOM messages " SF Markus Elfring
2016-07-02 19:29     ` Julia Lawall
2016-07-02 20:45   ` [PATCH 0/2] Input-at32psif: Fine-tuning for OOM handling " Joe Perches
2016-07-03  8:01     ` SF Markus Elfring
2016-07-13 22:01   ` Dmitry Torokhov
2016-09-24 11:07 ` [PATCH 0/2] Input-evdev: Fine-tuning for three function implementations SF Markus Elfring
2016-09-24 11:08   ` SF Markus Elfring [this message]
2016-09-24 17:54     ` [PATCH 1/2] Input-evdev: Use kmalloc_array() in evdev_handle_get_val() Dmitry Torokhov
2016-09-24 18:16       ` SF Markus Elfring
2016-09-24 18:34         ` Dmitry Torokhov
2016-09-24 19:04           ` SF Markus Elfring
2016-09-24 11:10   ` [PATCH 2/2] Input-evdev: Rename a jump label in two functions SF Markus Elfring
2016-09-24 17:47     ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a1f52e8-a502-1d4b-d9c9-e806cc6f246e@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rydberg@bitmath.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).