linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/18] Use kmemdup instead of kmalloc + memcpy
@ 2014-05-26 15:21 Benoit Taine
  2014-05-26 15:21 ` [PATCH 16/18] HID: uhid: " Benoit Taine
  0 siblings, 1 reply; 4+ messages in thread
From: Benoit Taine @ 2014-05-26 15:21 UTC (permalink / raw)
  To: linux-media
  Cc: benoit.taine, dri-devel, devel, netdev, linux-wireless, wcn36xx,
	linux-kernel, linux-usb, usb-storage, linux-scsi,
	DL-MPTFusionLinux, linux-input, kernel-janitors

These patches enhance kernel style usage, and allows smaller code while
preventing accidental code edits to produce overflows.

The semantic patch at scripts/coccinelle/api/memdup.cocci was used to
detect and edit this situation.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 16/18] HID: uhid: Use kmemdup instead of kmalloc + memcpy
  2014-05-26 15:21 [PATCH 0/18] Use kmemdup instead of kmalloc + memcpy Benoit Taine
@ 2014-05-26 15:21 ` Benoit Taine
  2014-05-26 15:33   ` David Herrmann
  2014-05-26 22:42   ` Jiri Kosina
  0 siblings, 2 replies; 4+ messages in thread
From: Benoit Taine @ 2014-05-26 15:21 UTC (permalink / raw)
  To: David Herrmann
  Cc: benoit.taine, Jiri Kosina, linux-input, linux-kernel,
	kernel-janitors

This issue was reported by coccicheck using the semantic patch 
at scripts/coccinelle/api/memdup.cocci

Signed-off-by: Benoit Taine <benoit.taine@lip6.fr>
---
Tested by compilation without errors.

 drivers/hid/uhid.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index 0d078c3..0cb92e3 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -441,12 +441,11 @@ static int uhid_dev_create2(struct uhid_device *uhid,
 	if (uhid->rd_size <= 0 || uhid->rd_size > HID_MAX_DESCRIPTOR_SIZE)
 		return -EINVAL;
 
-	uhid->rd_data = kmalloc(uhid->rd_size, GFP_KERNEL);
+	uhid->rd_data = kmemdup(ev->u.create2.rd_data, uhid->rd_size,
+				GFP_KERNEL);
 	if (!uhid->rd_data)
 		return -ENOMEM;
 
-	memcpy(uhid->rd_data, ev->u.create2.rd_data, uhid->rd_size);
-
 	hid = hid_allocate_device();
 	if (IS_ERR(hid)) {
 		ret = PTR_ERR(hid);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 16/18] HID: uhid: Use kmemdup instead of kmalloc + memcpy
  2014-05-26 15:21 ` [PATCH 16/18] HID: uhid: " Benoit Taine
@ 2014-05-26 15:33   ` David Herrmann
  2014-05-26 22:42   ` Jiri Kosina
  1 sibling, 0 replies; 4+ messages in thread
From: David Herrmann @ 2014-05-26 15:33 UTC (permalink / raw)
  To: Benoit Taine
  Cc: David Herrmann, Jiri Kosina, open list:HID CORE LAYER,
	linux-kernel, kernel-janitors@vger.kernel.org

Hi

On Mon, May 26, 2014 at 5:21 PM, Benoit Taine <benoit.taine@lip6.fr> wrote:
> This issue was reported by coccicheck using the semantic patch
> at scripts/coccinelle/api/memdup.cocci
>
> Signed-off-by: Benoit Taine <benoit.taine@lip6.fr>

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> ---
> Tested by compilation without errors.
>
>  drivers/hid/uhid.c |    5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
> index 0d078c3..0cb92e3 100644
> --- a/drivers/hid/uhid.c
> +++ b/drivers/hid/uhid.c
> @@ -441,12 +441,11 @@ static int uhid_dev_create2(struct uhid_device *uhid,
>         if (uhid->rd_size <= 0 || uhid->rd_size > HID_MAX_DESCRIPTOR_SIZE)
>                 return -EINVAL;
>
> -       uhid->rd_data = kmalloc(uhid->rd_size, GFP_KERNEL);
> +       uhid->rd_data = kmemdup(ev->u.create2.rd_data, uhid->rd_size,
> +                               GFP_KERNEL);
>         if (!uhid->rd_data)
>                 return -ENOMEM;
>
> -       memcpy(uhid->rd_data, ev->u.create2.rd_data, uhid->rd_size);
> -
>         hid = hid_allocate_device();
>         if (IS_ERR(hid)) {
>                 ret = PTR_ERR(hid);
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 16/18] HID: uhid: Use kmemdup instead of kmalloc + memcpy
  2014-05-26 15:21 ` [PATCH 16/18] HID: uhid: " Benoit Taine
  2014-05-26 15:33   ` David Herrmann
@ 2014-05-26 22:42   ` Jiri Kosina
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2014-05-26 22:42 UTC (permalink / raw)
  To: Benoit Taine; +Cc: David Herrmann, linux-input, linux-kernel, kernel-janitors

On Mon, 26 May 2014, Benoit Taine wrote:

> This issue was reported by coccicheck using the semantic patch 
> at scripts/coccinelle/api/memdup.cocci
> 
> Signed-off-by: Benoit Taine <benoit.taine@lip6.fr>

Applied, thanks Benoit.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-26 22:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-26 15:21 [PATCH 0/18] Use kmemdup instead of kmalloc + memcpy Benoit Taine
2014-05-26 15:21 ` [PATCH 16/18] HID: uhid: " Benoit Taine
2014-05-26 15:33   ` David Herrmann
2014-05-26 22:42   ` Jiri Kosina

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).