Skip to content

Commit

Permalink
usb: gadget: Use kmemdup instead of kmalloc + memcpy
Browse files Browse the repository at this point in the history
This issue was reported by coccicheck using the semantic patch
at scripts/coccinelle/api/memdup.cocci

Signed-off-by: Benoit Taine <benoit.taine@lip6.fr>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Benoit Taine authored and Felipe Balbi committed Jun 30, 2014
1 parent eac44dc commit 58b949e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
4 changes: 1 addition & 3 deletions drivers/usb/gadget/configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,12 +1021,10 @@ static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop,

if (page[len - 1] == '\n' || page[len - 1] == '\0')
--len;
new_data = kzalloc(len, GFP_KERNEL);
new_data = kmemdup(page, len, GFP_KERNEL);
if (!new_data)
return -ENOMEM;

memcpy(new_data, page, len);

if (desc->opts_mutex)
mutex_lock(desc->opts_mutex);
kfree(ext_prop->data);
Expand Down
3 changes: 1 addition & 2 deletions drivers/usb/gadget/lpc32xx_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3045,11 +3045,10 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
dma_addr_t dma_handle;
struct device_node *isp1301_node;

udc = kzalloc(sizeof(*udc), GFP_KERNEL);
udc = kmemdup(&controller_template, sizeof(*udc), GFP_KERNEL);
if (!udc)
return -ENOMEM;

memcpy(udc, &controller_template, sizeof(*udc));
for (i = 0; i <= 15; i++)
udc->ep[i].udc = udc;
udc->gadget.ep0 = &udc->ep[0].ep;
Expand Down

0 comments on commit 58b949e

Please sign in to comment.