netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: Use kmemdup instead of kmalloc and memcpy
@ 2016-12-23 19:14 Shyam Saini
  2016-12-28  1:16 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Shyam Saini @ 2016-12-23 19:14 UTC (permalink / raw)
  To: mst; +Cc: jasowang, virtualization, netdev, Shyam Saini

when some other buffer is immediately copied into allocated region.
Replace calls to kmalloc followed by a memcpy with a direct
call to kmemdup.

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
---
 drivers/net/virtio_net.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ba1aa24..dde4bc4 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1206,10 +1206,9 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p)
 	struct sockaddr *addr;
 	struct scatterlist sg;
 
-	addr = kmalloc(sizeof(*addr), GFP_KERNEL);
+	addr = kmemdup(p, sizeof(*addr), GFP_KERNEL);
 	if (!addr)
 		return -ENOMEM;
-	memcpy(addr, p, sizeof(*addr));
 
 	ret = eth_prepare_mac_addr_change(dev, addr);
 	if (ret)
-- 
2.7.4

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

* Re: [PATCH] net: Use kmemdup instead of kmalloc and memcpy
  2016-12-23 19:14 [PATCH] net: Use kmemdup instead of kmalloc and memcpy Shyam Saini
@ 2016-12-28  1:16 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-12-28  1:16 UTC (permalink / raw)
  To: mayhs11saini; +Cc: netdev, virtualization, mst

From: Shyam Saini <mayhs11saini@gmail.com>
Date: Sat, 24 Dec 2016 00:44:58 +0530

> when some other buffer is immediately copied into allocated region.
> Replace calls to kmalloc followed by a memcpy with a direct
> call to kmemdup.
> 
> Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>

Applied.

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

end of thread, other threads:[~2016-12-28  1:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-23 19:14 [PATCH] net: Use kmemdup instead of kmalloc and memcpy Shyam Saini
2016-12-28  1:16 ` David Miller

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