Patchwork net: dns_resolver: Use kmemdup instead of kmalloc and memcpy

login
register
mail settings
Submitter Alexandru Gheorghiu
Date March 15, 2013, 6:21 p.m.
Message ID <1363371712-11566-1-git-send-email-gheorghiuandru@gmail.com>
Download mbox | patch
Permalink /patch/228136/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Alexandru Gheorghiu - March 15, 2013, 6:21 p.m.
Replace use of kmalloc followed by memcpy with kmemdup.
Patch found using coccinelle.

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
 net/dns_resolver/dns_query.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Patch

diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index c32be29..4ac62fb 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -146,11 +146,10 @@  int dns_query(const char *type, const char *name, size_t namelen,
 	len = upayload->datalen;
 
 	ret = -ENOMEM;
-	*_result = kmalloc(len + 1, GFP_KERNEL);
+	*_result = kmemdup(upayload->data, len + 1, GFP_KERNEL);
 	if (!*_result)
 		goto put;
 
-	memcpy(*_result, upayload->data, len + 1);
 	if (_expiry)
 		*_expiry = rkey->expiry;