Patchwork CDC NCM: Use kzalloc rather than kmalloc followed by memset with 0

login
register
mail settings
Submitter Thomas Meyer
Date Nov. 17, 2011, 10:43 p.m.
Message ID <1321569820.1624.264.camel@localhost.localdomain>
Download mbox | patch
Permalink /patch/127067/
State Accepted
Delegated to: David Miller
Headers show

Comments

Thomas Meyer - Nov. 17, 2011, 10:43 p.m.
This considers some simple cases that are common and easy to validate
Note in particular that there are no ...s in the rule, so all of the
matched code has to be contiguous

The semantic patch that makes this change is available
in scripts/coccinelle/api/alloc/kzalloc-simple.cocci.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - Nov. 22, 2011, 8:58 p.m.
From: Thomas Meyer <thomas@m3y3r.de>
Date: Thu, 17 Nov 2011 23:43:40 +0100

> This considers some simple cases that are common and easy to validate
> Note in particular that there are no ...s in the rule, so all of the
> matched code has to be contiguous
> 
> The semantic patch that makes this change is available
> in scripts/coccinelle/api/alloc/kzalloc-simple.cocci.
> 
> Signed-off-by: Thomas Meyer <thomas@m3y3r.de>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff -u -p a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
--- a/drivers/net/usb/cdc_ncm.c 2011-11-07 19:38:00.160137318 +0100
+++ b/drivers/net/usb/cdc_ncm.c 2011-11-08 09:35:34.632578608 +0100
@@ -465,12 +465,10 @@  static int cdc_ncm_bind(struct usbnet *d
 	int temp;
 	u8 iface_no;
 
-	ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
 	if (ctx == NULL)
 		return -ENODEV;
 
-	memset(ctx, 0, sizeof(*ctx));
-
 	init_timer(&ctx->tx_timer);
 	spin_lock_init(&ctx->mtx);
 	ctx->netdev = dev->net;