USB: oxu210hp-hcd.c: use devm_ functions

This patch introduces the use of devm_ioremap_resource instead of
request_mem_region and ioremap. The error handling on
platform_get_resource and the error message for ioremap are removed. The
function devm_kzalloc replaces memory allocation by unmanaged kzalloc. The
function calls to free the allocated memory in the probe and remove
functions are done away with. Some labels are removed and a label error
is added to make is less specific to the context. The debug message is
removed as devm_ioremap generates debug messages of its own.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Himangi Saraogi 2014-06-29 12:37:44 +05:30 committed by Greg Kroah-Hartman
parent 2097937467
commit 8968614a8c
1 changed files with 9 additions and 39 deletions

View File

@ -3826,49 +3826,36 @@ static int oxu_drv_probe(struct platform_device *pdev)
dev_dbg(&pdev->dev, "IRQ resource %d\n", irq);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "no registers address! Check %s setup!\n",
dev_name(&pdev->dev));
return -ENODEV;
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base)) {
ret = PTR_ERR(base);
goto error;
}
memstart = res->start;
memlen = resource_size(res);
dev_dbg(&pdev->dev, "MEM resource %lx-%lx\n", memstart, memlen);
if (!request_mem_region(memstart, memlen,
oxu_hc_driver.description)) {
dev_dbg(&pdev->dev, "memory area already in use\n");
return -EBUSY;
}
ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING);
if (ret) {
dev_err(&pdev->dev, "error setting irq type\n");
ret = -EFAULT;
goto error_set_irq_type;
}
base = ioremap(memstart, memlen);
if (!base) {
dev_dbg(&pdev->dev, "error mapping memory\n");
ret = -EFAULT;
goto error_ioremap;
goto error;
}
/* Allocate a driver data struct to hold useful info for both
* SPH & OTG devices
*/
info = kzalloc(sizeof(struct oxu_info), GFP_KERNEL);
info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL);
if (!info) {
dev_dbg(&pdev->dev, "error allocating memory\n");
ret = -EFAULT;
goto error_alloc;
goto error;
}
platform_set_drvdata(pdev, info);
ret = oxu_init(pdev, memstart, memlen, base, irq);
if (ret < 0) {
dev_dbg(&pdev->dev, "cannot init USB devices\n");
goto error_init;
goto error;
}
dev_info(&pdev->dev, "devices enabled and running\n");
@ -3876,16 +3863,7 @@ static int oxu_drv_probe(struct platform_device *pdev)
return 0;
error_init:
kfree(info);
error_alloc:
iounmap(base);
error_set_irq_type:
error_ioremap:
release_mem_region(memstart, memlen);
error:
dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
return ret;
}
@ -3899,18 +3877,10 @@ static void oxu_remove(struct platform_device *pdev, struct usb_hcd *hcd)
static int oxu_drv_remove(struct platform_device *pdev)
{
struct oxu_info *info = platform_get_drvdata(pdev);
unsigned long memstart = info->hcd[0]->rsrc_start,
memlen = info->hcd[0]->rsrc_len;
void *base = info->hcd[0]->regs;
oxu_remove(pdev, info->hcd[0]);
oxu_remove(pdev, info->hcd[1]);
iounmap(base);
release_mem_region(memstart, memlen);
kfree(info);
return 0;
}