Skip to contentSkip to conversation

net: Use kmemdup rather than duplicating its implementation

PATCH Applied Thomas Meyer 4 participants 4 messages Nov 17, 2011 – Nov 21, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Use kmemdup rather than duplicating its implementation

The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci.

---

net/irda/irttp.c 2011-11-08 10:59:07.152748948 +0100 renamed from net/irda/irttp.c 2011-11-07 19:39:06.071138486 +0100 +1 -2
diff -u -p a/net/irda/irttp.c b/net/irda/irttp.c
@@ -1461,14 +1461,13 @@ struct tsap_cb *irttp_dup(struct tsap_cb
 	}
 
 	/* Allocate a new instance */
-	new = kmalloc(sizeof(struct tsap_cb), GFP_ATOMIC);
+	new = kmemdup(orig, sizeof(struct tsap_cb), GFP_ATOMIC);
 	if (!new) {
 		IRDA_DEBUG(0, "%s(), unable to kmalloc\n", __func__);
 		spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
 		return NULL;
 	}
 	/* Dup */
-	memcpy(new, orig, sizeof(struct tsap_cb));
 	spin_lock_init(&new->lock);
 
 	/* We don't need the old instance any more */
#1 lore raw
Quoted 5 lines · Thomas Meyer

The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci.

---

Similarly this is for the specific driver 'irttp' and not generally 'net'.

Ben.

Quoted 19 lines

diff -u -p a/net/irda/irttp.c b/net/irda/irttp.c

net/irda/irttp.c 2011-11-08 10:59:07.152748948 +0100 renamed from net/irda/irttp.c 2011-11-07 19:39:06.071138486 +0100 +1 -2
@@ -1461,14 +1461,13 @@ struct tsap_cb *irttp_dup(struct tsap_cb
 	}
 
 	/* Allocate a new instance */
-	new = kmalloc(sizeof(struct tsap_cb), GFP_ATOMIC);
+	new = kmemdup(orig, sizeof(struct tsap_cb), GFP_ATOMIC);
 	if (!new) {
 		IRDA_DEBUG(0, "%s(), unable to kmalloc\n", __func__);
 		spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
 		return NULL;
 	}
 	/* Dup */
-	memcpy(new, orig, sizeof(struct tsap_cb));
 	spin_lock_init(&new->lock);
 
 	/* We don't need the old instance any more */
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#2 lore raw
In reply to Thomas Meyer
Quoted 11 lines · On Thu, 17 Nov 2011 14:43:40 -0800 Thomas Meyer <[email protected]> wrote:

The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci.

---

diff -u -p a/net/irda/irttp.c b/net/irda/irttp.c

net/irda/irttp.c 2011-11-08 10:59:07.152748948 +0100 renamed from net/irda/irttp.c 2011-11-07 19:39:06.071138486 +0100 +0 -0
@@ -1461,14 +1461,13 @@ struct tsap_cb *irttp_dup(struct tsap_cb
 	}

net/irda/irttp.c 2011-11-08 10:59:07.152748948 +0100 struct tsap_cb *irttp_dup(struct tsap_cb · line 1470

Quoted 10 lines
net/irda/irttp.c 2011-11-08 10:59:07.152748948 +0100 renamed from net/irda/irttp.c 2011-11-07 19:39:06.071138486 +0100 +1 -1
 
 	/* Allocate a new instance */
-	new = kmalloc(sizeof(struct tsap_cb), GFP_ATOMIC);
+	new = kmemdup(orig, sizeof(struct tsap_cb), GFP_ATOMIC);
 	if (!new) {
 		IRDA_DEBUG(0, "%s(), unable to kmalloc\n", __func__);
 		spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
 		return NULL;
 	}
 	/* Dup */

this ^^^ comment should be removed also.

Quoted 4 lines
net/irda/irttp.c 2011-11-08 10:59:07.152748948 +0100 renamed from net/irda/irttp.c 2011-11-07 19:39:06.071138486 +0100 +0 -1
-	memcpy(new, orig, sizeof(struct tsap_cb));
 	spin_lock_init(&new->lock);
 
 	/* We don't need the old instance any more */