Skip to content

Commit

Permalink
net: Use kmemdup instead of kmalloc and memcpy
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Shyam Saini authored and David S. Miller committed Dec 29, 2016
1 parent 5671e8c commit 801822d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,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)
Expand Down

0 comments on commit 801822d

Please sign in to comment.