Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1490650 > unrolled thread

[PATCH 1/4] Input-gameport: Use kmalloc_array() in joydump_connect()

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2016-09-24 15:50 +0200
Last post2016-09-24 19:10 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/4] Input-gameport: Use kmalloc_array() in joydump_connect() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-24 15:50 +0200
    Re: [PATCH 1/4] Input-gameport: Use kmalloc_array() in  joydump_connect() Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-09-24 18:50 +0200
      Re: Input-gameport: Use kmalloc_array() in joydump_connect() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-24 19:10 +0200

#1490650 — [PATCH 1/4] Input-gameport: Use kmalloc_array() in joydump_connect()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-09-24 15:50 +0200
Subject[PATCH 1/4] Input-gameport: Use kmalloc_array() in joydump_connect()
Message-ID<skVv3-1Az-21@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 24 Sep 2016 13:50:20 +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 structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/input/joystick/joydump.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
index d1c6e48..e515058 100644
--- a/drivers/input/joystick/joydump.c
+++ b/drivers/input/joystick/joydump.c
@@ -79,8 +79,7 @@ static int joydump_connect(struct gameport *gameport, struct gameport_driver *dr
 	}
 
 	timeout = gameport_time(gameport, 10000); /* 10 ms */
-
-	buf = kmalloc(BUF_SIZE * sizeof(struct joydump), GFP_KERNEL);
+	buf = kmalloc_array(BUF_SIZE, sizeof(*buf), GFP_KERNEL);
 	if (!buf) {
 		printk(KERN_INFO "joydump: no memory for testing\n");
 		goto jd_end;
-- 
2.10.0

[toc] | [next] | [standalone]


#1490681 — Re: [PATCH 1/4] Input-gameport: Use kmalloc_array() in joydump_connect()

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2016-09-24 18:50 +0200
SubjectRe: [PATCH 1/4] Input-gameport: Use kmalloc_array() in joydump_connect()
Message-ID<skYjf-3o6-5@gated-at.bofh.it>
In reply to#1490650
On Sat, Sep 24, 2016 at 03:46:21PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 24 Sep 2016 13:50:20 +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".
> 

-ENOPARSE.

>   This issue was detected by using the Coccinelle software.
> 
> * Replace the specification of a data structure by a pointer dereference
>   to make the corresponding size determination a bit safer according to
>   the Linux coding style convention.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/input/joystick/joydump.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
> index d1c6e48..e515058 100644
> --- a/drivers/input/joystick/joydump.c
> +++ b/drivers/input/joystick/joydump.c
> @@ -79,8 +79,7 @@ static int joydump_connect(struct gameport *gameport, struct gameport_driver *dr
>  	}
>  
>  	timeout = gameport_time(gameport, 10000); /* 10 ms */
> -
> -	buf = kmalloc(BUF_SIZE * sizeof(struct joydump), GFP_KERNEL);
> +	buf = kmalloc_array(BUF_SIZE, sizeof(*buf), GFP_KERNEL);
>  	if (!buf) {
>  		printk(KERN_INFO "joydump: no memory for testing\n");
>  		goto jd_end;
> -- 
> 2.10.0
> 

-- 
Dmitry

[toc] | [prev] | [next] | [standalone]


#1490689 — Re: Input-gameport: Use kmalloc_array() in joydump_connect()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-09-24 19:10 +0200
SubjectRe: Input-gameport: Use kmalloc_array() in joydump_connect()
Message-ID<skYCC-3JI-19@gated-at.bofh.it>
In reply to#1490681
>> * 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".
>>
> 
> -ENOPARSE.

Do you find an other wording better?


The script "checkpatch.pl" can point information out like the following.

WARNING: Prefer kmalloc_array over kmalloc with multiply


Regards,
Markus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web