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:
parent
2097937467
commit
8968614a8c
1 changed files with 9 additions and 39 deletions
|
@ -3826,49 +3826,36 @@ static int oxu_drv_probe(struct platform_device *pdev)
|
||||||
dev_dbg(&pdev->dev, "IRQ resource %d\n", irq);
|
dev_dbg(&pdev->dev, "IRQ resource %d\n", irq);
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (!res) {
|
base = devm_ioremap_resource(&pdev->dev, res);
|
||||||
dev_err(&pdev->dev, "no registers address! Check %s setup!\n",
|
if (IS_ERR(base)) {
|
||||||
dev_name(&pdev->dev));
|
ret = PTR_ERR(base);
|
||||||
return -ENODEV;
|
goto error;
|
||||||
}
|
}
|
||||||
memstart = res->start;
|
memstart = res->start;
|
||||||
memlen = resource_size(res);
|
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);
|
ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "error setting irq type\n");
|
dev_err(&pdev->dev, "error setting irq type\n");
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto error_set_irq_type;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
base = ioremap(memstart, memlen);
|
|
||||||
if (!base) {
|
|
||||||
dev_dbg(&pdev->dev, "error mapping memory\n");
|
|
||||||
ret = -EFAULT;
|
|
||||||
goto error_ioremap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a driver data struct to hold useful info for both
|
/* Allocate a driver data struct to hold useful info for both
|
||||||
* SPH & OTG devices
|
* SPH & OTG devices
|
||||||
*/
|
*/
|
||||||
info = kzalloc(sizeof(struct oxu_info), GFP_KERNEL);
|
info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
dev_dbg(&pdev->dev, "error allocating memory\n");
|
dev_dbg(&pdev->dev, "error allocating memory\n");
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto error_alloc;
|
goto error;
|
||||||
}
|
}
|
||||||
platform_set_drvdata(pdev, info);
|
platform_set_drvdata(pdev, info);
|
||||||
|
|
||||||
ret = oxu_init(pdev, memstart, memlen, base, irq);
|
ret = oxu_init(pdev, memstart, memlen, base, irq);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_dbg(&pdev->dev, "cannot init USB devices\n");
|
dev_dbg(&pdev->dev, "cannot init USB devices\n");
|
||||||
goto error_init;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_info(&pdev->dev, "devices enabled and running\n");
|
dev_info(&pdev->dev, "devices enabled and running\n");
|
||||||
|
@ -3876,16 +3863,7 @@ static int oxu_drv_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_init:
|
error:
|
||||||
kfree(info);
|
|
||||||
|
|
||||||
error_alloc:
|
|
||||||
iounmap(base);
|
|
||||||
|
|
||||||
error_set_irq_type:
|
|
||||||
error_ioremap:
|
|
||||||
release_mem_region(memstart, memlen);
|
|
||||||
|
|
||||||
dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
|
dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
|
||||||
return 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)
|
static int oxu_drv_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct oxu_info *info = platform_get_drvdata(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[0]);
|
||||||
oxu_remove(pdev, info->hcd[1]);
|
oxu_remove(pdev, info->hcd[1]);
|
||||||
|
|
||||||
iounmap(base);
|
|
||||||
release_mem_region(memstart, memlen);
|
|
||||||
|
|
||||||
kfree(info);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue