Skip to content

Commit

Permalink
usb: gadget: fsl_qe_udc: Introduce use of managed version of kzalloc
Browse files Browse the repository at this point in the history
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, the unnecesary labels are removed and some labels are
renamed to preserve ordering.

The following Coccinelle semantic patch was used for making the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
  .probe = probefn,
  .remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
  <+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
  ...
?-kfree(e);
  ...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
  <...
- kfree(e);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Himangi Saraogi authored and Felipe Balbi committed Jun 30, 2014
1 parent 885162d commit 7b0a12a
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions drivers/usb/gadget/fsl_qe_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2539,18 +2539,18 @@ static int qe_udc_probe(struct platform_device *ofdev)
goto err2;

/* create a buf for ZLP send, need to remain zeroed */
udc->nullbuf = kzalloc(256, GFP_KERNEL);
udc->nullbuf = devm_kzalloc(&ofdev->dev, 256, GFP_KERNEL);
if (udc->nullbuf == NULL) {
dev_err(udc->dev, "cannot alloc nullbuf\n");
ret = -ENOMEM;
goto err3;
}

/* buffer for data of get_status request */
udc->statusbuf = kzalloc(2, GFP_KERNEL);
udc->statusbuf = devm_kzalloc(&ofdev->dev, 2, GFP_KERNEL);
if (udc->statusbuf == NULL) {
ret = -ENOMEM;
goto err4;
goto err3;
}

udc->nullp = virt_to_phys((void *)udc->nullbuf);
Expand Down Expand Up @@ -2581,23 +2581,23 @@ static int qe_udc_probe(struct platform_device *ofdev)
if (ret) {
dev_err(udc->dev, "cannot request irq %d err %d\n",
udc->usb_irq, ret);
goto err5;
goto err4;
}

ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget,
qe_udc_release);
if (ret)
goto err6;
goto err5;

platform_set_drvdata(ofdev, udc);
dev_info(udc->dev,
"%s USB controller initialized as device\n",
(udc->soc_type == PORT_QE) ? "QE" : "CPM");
return 0;

err6:
free_irq(udc->usb_irq, udc);
err5:
free_irq(udc->usb_irq, udc);
err4:
irq_dispose_mapping(udc->usb_irq);
err_noirq:
if (udc->nullmap) {
Expand All @@ -2610,9 +2610,6 @@ static int qe_udc_probe(struct platform_device *ofdev)
udc->nullp, 256,
DMA_TO_DEVICE);
}
kfree(udc->statusbuf);
err4:
kfree(udc->nullbuf);
err3:
ep = &udc->eps[0];
cpm_muram_free(cpm_muram_offset(ep->rxbase));
Expand Down Expand Up @@ -2660,8 +2657,6 @@ static int qe_udc_remove(struct platform_device *ofdev)
udc->nullp, 256,
DMA_TO_DEVICE);
}
kfree(udc->statusbuf);
kfree(udc->nullbuf);

ep = &udc->eps[0];
cpm_muram_free(cpm_muram_offset(ep->rxbase));
Expand Down

0 comments on commit 7b0a12a

Please sign in to comment.