Commit e6789cd3 authored by Michal Simek's avatar Michal Simek Committed by Greg Kroah-Hartman

uio: Simplify uio error path by using devres functions

Using devres functions simplify driver error path.
- Use devm_kzalloc
- Use devm_request_irq
Signed-off-by: default avatarMichal Simek <michal.simek@xilinx.com>
Reviewed-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 497b46db
...@@ -796,10 +796,9 @@ int __uio_register_device(struct module *owner, ...@@ -796,10 +796,9 @@ int __uio_register_device(struct module *owner,
info->uio_dev = NULL; info->uio_dev = NULL;
idev = kzalloc(sizeof(*idev), GFP_KERNEL); idev = devm_kzalloc(parent, sizeof(*idev), GFP_KERNEL);
if (!idev) { if (!idev) {
ret = -ENOMEM; return -ENOMEM;
goto err_kzalloc;
} }
idev->owner = owner; idev->owner = owner;
...@@ -809,7 +808,7 @@ int __uio_register_device(struct module *owner, ...@@ -809,7 +808,7 @@ int __uio_register_device(struct module *owner,
ret = uio_get_minor(idev); ret = uio_get_minor(idev);
if (ret) if (ret)
goto err_get_minor; return ret;
idev->dev = device_create(&uio_class, parent, idev->dev = device_create(&uio_class, parent,
MKDEV(uio_major, idev->minor), idev, MKDEV(uio_major, idev->minor), idev,
...@@ -827,7 +826,7 @@ int __uio_register_device(struct module *owner, ...@@ -827,7 +826,7 @@ int __uio_register_device(struct module *owner,
info->uio_dev = idev; info->uio_dev = idev;
if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) { if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) {
ret = request_irq(info->irq, uio_interrupt, ret = devm_request_irq(parent, info->irq, uio_interrupt,
info->irq_flags, info->name, idev); info->irq_flags, info->name, idev);
if (ret) if (ret)
goto err_request_irq; goto err_request_irq;
...@@ -841,9 +840,6 @@ int __uio_register_device(struct module *owner, ...@@ -841,9 +840,6 @@ int __uio_register_device(struct module *owner,
device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
err_device_create: err_device_create:
uio_free_minor(idev); uio_free_minor(idev);
err_get_minor:
kfree(idev);
err_kzalloc:
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(__uio_register_device); EXPORT_SYMBOL_GPL(__uio_register_device);
...@@ -864,13 +860,9 @@ void uio_unregister_device(struct uio_info *info) ...@@ -864,13 +860,9 @@ void uio_unregister_device(struct uio_info *info)
uio_free_minor(idev); uio_free_minor(idev);
if (info->irq && (info->irq != UIO_IRQ_CUSTOM))
free_irq(info->irq, idev);
uio_dev_del_attributes(idev); uio_dev_del_attributes(idev);
device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
kfree(idev);
return; return;
} }
......
...@@ -112,11 +112,11 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) ...@@ -112,11 +112,11 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)
if (pdev->dev.of_node) { if (pdev->dev.of_node) {
/* alloc uioinfo for one device */ /* alloc uioinfo for one device */
uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL); uioinfo = devm_kzalloc(&pdev->dev, sizeof(*uioinfo),
GFP_KERNEL);
if (!uioinfo) { if (!uioinfo) {
ret = -ENOMEM;
dev_err(&pdev->dev, "unable to kmalloc\n"); dev_err(&pdev->dev, "unable to kmalloc\n");
return ret; return -ENOMEM;
} }
uioinfo->name = pdev->dev.of_node->name; uioinfo->name = pdev->dev.of_node->name;
uioinfo->version = "devicetree"; uioinfo->version = "devicetree";
...@@ -125,20 +125,19 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) ...@@ -125,20 +125,19 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)
if (!uioinfo || !uioinfo->name || !uioinfo->version) { if (!uioinfo || !uioinfo->name || !uioinfo->version) {
dev_err(&pdev->dev, "missing platform_data\n"); dev_err(&pdev->dev, "missing platform_data\n");
goto bad0; return ret;
} }
if (uioinfo->handler || uioinfo->irqcontrol || if (uioinfo->handler || uioinfo->irqcontrol ||
uioinfo->irq_flags & IRQF_SHARED) { uioinfo->irq_flags & IRQF_SHARED) {
dev_err(&pdev->dev, "interrupt configuration error\n"); dev_err(&pdev->dev, "interrupt configuration error\n");
goto bad0; return ret;
} }
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
ret = -ENOMEM;
dev_err(&pdev->dev, "unable to kmalloc\n"); dev_err(&pdev->dev, "unable to kmalloc\n");
goto bad0; return -ENOMEM;
} }
priv->uioinfo = uioinfo; priv->uioinfo = uioinfo;
...@@ -153,7 +152,7 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) ...@@ -153,7 +152,7 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)
uioinfo->irq = UIO_IRQ_NONE; uioinfo->irq = UIO_IRQ_NONE;
else if (ret < 0) { else if (ret < 0) {
dev_err(&pdev->dev, "failed to get IRQ\n"); dev_err(&pdev->dev, "failed to get IRQ\n");
goto bad1; return ret;
} }
} }
...@@ -209,20 +208,12 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) ...@@ -209,20 +208,12 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)
ret = uio_register_device(&pdev->dev, priv->uioinfo); ret = uio_register_device(&pdev->dev, priv->uioinfo);
if (ret) { if (ret) {
dev_err(&pdev->dev, "unable to register uio device\n"); dev_err(&pdev->dev, "unable to register uio device\n");
goto bad2; pm_runtime_disable(&pdev->dev);
return ret;
} }
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
return 0; return 0;
bad2:
pm_runtime_disable(&pdev->dev);
bad1:
kfree(priv);
bad0:
/* kfree uioinfo for OF */
if (pdev->dev.of_node)
kfree(uioinfo);
return ret;
} }
static int uio_pdrv_genirq_remove(struct platform_device *pdev) static int uio_pdrv_genirq_remove(struct platform_device *pdev)
...@@ -235,11 +226,6 @@ static int uio_pdrv_genirq_remove(struct platform_device *pdev) ...@@ -235,11 +226,6 @@ static int uio_pdrv_genirq_remove(struct platform_device *pdev)
priv->uioinfo->handler = NULL; priv->uioinfo->handler = NULL;
priv->uioinfo->irqcontrol = NULL; priv->uioinfo->irqcontrol = NULL;
/* kfree uioinfo for OF */
if (pdev->dev.of_node)
kfree(priv->uioinfo);
kfree(priv);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment