diff options
| author | Michal Simek <michal.simek@xilinx.com> | 2013-09-12 01:39:59 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-09-26 11:46:45 -0400 |
| commit | e6789cd3dfb553077606ccafeb05e0043f072481 (patch) | |
| tree | cb589b8f1a73343a8a67153a75ed9384a9cd0621 /drivers/uio | |
| parent | 497b46dbc660d53e94abf8a46cda9747023802ba (diff) | |
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: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/uio')
| -rw-r--r-- | drivers/uio/uio.c | 16 | ||||
| -rw-r--r-- | drivers/uio/uio_pdrv_genirq.c | 34 |
2 files changed, 14 insertions, 36 deletions
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index ba475632c5fa..11d4e0a52579 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c | |||
| @@ -796,10 +796,9 @@ int __uio_register_device(struct module *owner, | |||
| 796 | 796 | ||
| 797 | info->uio_dev = NULL; | 797 | info->uio_dev = NULL; |
| 798 | 798 | ||
| 799 | idev = kzalloc(sizeof(*idev), GFP_KERNEL); | 799 | idev = devm_kzalloc(parent, sizeof(*idev), GFP_KERNEL); |
| 800 | if (!idev) { | 800 | if (!idev) { |
| 801 | ret = -ENOMEM; | 801 | return -ENOMEM; |
| 802 | goto err_kzalloc; | ||
| 803 | } | 802 | } |
| 804 | 803 | ||
| 805 | idev->owner = owner; | 804 | idev->owner = owner; |
| @@ -809,7 +808,7 @@ int __uio_register_device(struct module *owner, | |||
| 809 | 808 | ||
| 810 | ret = uio_get_minor(idev); | 809 | ret = uio_get_minor(idev); |
| 811 | if (ret) | 810 | if (ret) |
| 812 | goto err_get_minor; | 811 | return ret; |
| 813 | 812 | ||
| 814 | idev->dev = device_create(&uio_class, parent, | 813 | idev->dev = device_create(&uio_class, parent, |
| 815 | MKDEV(uio_major, idev->minor), idev, | 814 | MKDEV(uio_major, idev->minor), idev, |
| @@ -827,7 +826,7 @@ int __uio_register_device(struct module *owner, | |||
| 827 | info->uio_dev = idev; | 826 | info->uio_dev = idev; |
| 828 | 827 | ||
| 829 | if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) { | 828 | if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) { |
| 830 | ret = request_irq(info->irq, uio_interrupt, | 829 | ret = devm_request_irq(parent, info->irq, uio_interrupt, |
| 831 | info->irq_flags, info->name, idev); | 830 | info->irq_flags, info->name, idev); |
| 832 | if (ret) | 831 | if (ret) |
| 833 | goto err_request_irq; | 832 | goto err_request_irq; |
| @@ -841,9 +840,6 @@ err_uio_dev_add_attributes: | |||
| 841 | device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); | 840 | device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); |
| 842 | err_device_create: | 841 | err_device_create: |
| 843 | uio_free_minor(idev); | 842 | uio_free_minor(idev); |
| 844 | err_get_minor: | ||
| 845 | kfree(idev); | ||
| 846 | err_kzalloc: | ||
| 847 | return ret; | 843 | return ret; |
| 848 | } | 844 | } |
| 849 | EXPORT_SYMBOL_GPL(__uio_register_device); | 845 | EXPORT_SYMBOL_GPL(__uio_register_device); |
| @@ -864,13 +860,9 @@ void uio_unregister_device(struct uio_info *info) | |||
| 864 | 860 | ||
| 865 | uio_free_minor(idev); | 861 | uio_free_minor(idev); |
| 866 | 862 | ||
| 867 | if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) | ||
| 868 | free_irq(info->irq, idev); | ||
| 869 | |||
| 870 | uio_dev_del_attributes(idev); | 863 | uio_dev_del_attributes(idev); |
| 871 | 864 | ||
| 872 | device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); | 865 | device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); |
| 873 | kfree(idev); | ||
| 874 | 866 | ||
| 875 | return; | 867 | return; |
| 876 | } | 868 | } |
diff --git a/drivers/uio/uio_pdrv_genirq.c b/drivers/uio/uio_pdrv_genirq.c index 90ff17a0202f..76669313e9a7 100644 --- a/drivers/uio/uio_pdrv_genirq.c +++ b/drivers/uio/uio_pdrv_genirq.c | |||
| @@ -112,11 +112,11 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) | |||
| 112 | 112 | ||
| 113 | if (pdev->dev.of_node) { | 113 | if (pdev->dev.of_node) { |
| 114 | /* alloc uioinfo for one device */ | 114 | /* alloc uioinfo for one device */ |
| 115 | uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL); | 115 | uioinfo = devm_kzalloc(&pdev->dev, sizeof(*uioinfo), |
| 116 | GFP_KERNEL); | ||
| 116 | if (!uioinfo) { | 117 | if (!uioinfo) { |
| 117 | ret = -ENOMEM; | ||
| 118 | dev_err(&pdev->dev, "unable to kmalloc\n"); | 118 | dev_err(&pdev->dev, "unable to kmalloc\n"); |
| 119 | return ret; | 119 | return -ENOMEM; |
| 120 | } | 120 | } |
| 121 | uioinfo->name = pdev->dev.of_node->name; | 121 | uioinfo->name = pdev->dev.of_node->name; |
| 122 | uioinfo->version = "devicetree"; | 122 | uioinfo->version = "devicetree"; |
| @@ -125,20 +125,19 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) | |||
| 125 | 125 | ||
| 126 | if (!uioinfo || !uioinfo->name || !uioinfo->version) { | 126 | if (!uioinfo || !uioinfo->name || !uioinfo->version) { |
| 127 | dev_err(&pdev->dev, "missing platform_data\n"); | 127 | dev_err(&pdev->dev, "missing platform_data\n"); |
| 128 | goto bad0; | 128 | return ret; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | if (uioinfo->handler || uioinfo->irqcontrol || | 131 | if (uioinfo->handler || uioinfo->irqcontrol || |
| 132 | uioinfo->irq_flags & IRQF_SHARED) { | 132 | uioinfo->irq_flags & IRQF_SHARED) { |
| 133 | dev_err(&pdev->dev, "interrupt configuration error\n"); | 133 | dev_err(&pdev->dev, "interrupt configuration error\n"); |
| 134 | goto bad0; | 134 | return ret; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | 137 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 138 | if (!priv) { | 138 | if (!priv) { |
| 139 | ret = -ENOMEM; | ||
| 140 | dev_err(&pdev->dev, "unable to kmalloc\n"); | 139 | dev_err(&pdev->dev, "unable to kmalloc\n"); |
| 141 | goto bad0; | 140 | return -ENOMEM; |
| 142 | } | 141 | } |
| 143 | 142 | ||
| 144 | priv->uioinfo = uioinfo; | 143 | priv->uioinfo = uioinfo; |
| @@ -153,7 +152,7 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) | |||
| 153 | uioinfo->irq = UIO_IRQ_NONE; | 152 | uioinfo->irq = UIO_IRQ_NONE; |
| 154 | else if (ret < 0) { | 153 | else if (ret < 0) { |
| 155 | dev_err(&pdev->dev, "failed to get IRQ\n"); | 154 | dev_err(&pdev->dev, "failed to get IRQ\n"); |
| 156 | goto bad1; | 155 | return ret; |
| 157 | } | 156 | } |
| 158 | } | 157 | } |
| 159 | 158 | ||
| @@ -209,20 +208,12 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) | |||
| 209 | ret = uio_register_device(&pdev->dev, priv->uioinfo); | 208 | ret = uio_register_device(&pdev->dev, priv->uioinfo); |
| 210 | if (ret) { | 209 | if (ret) { |
| 211 | dev_err(&pdev->dev, "unable to register uio device\n"); | 210 | dev_err(&pdev->dev, "unable to register uio device\n"); |
| 212 | goto bad2; | 211 | pm_runtime_disable(&pdev->dev); |
| 212 | return ret; | ||
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | platform_set_drvdata(pdev, priv); | 215 | platform_set_drvdata(pdev, priv); |
| 216 | return 0; | 216 | return 0; |
| 217 | bad2: | ||
| 218 | pm_runtime_disable(&pdev->dev); | ||
| 219 | bad1: | ||
| 220 | kfree(priv); | ||
| 221 | bad0: | ||
| 222 | /* kfree uioinfo for OF */ | ||
| 223 | if (pdev->dev.of_node) | ||
| 224 | kfree(uioinfo); | ||
| 225 | return ret; | ||
| 226 | } | 217 | } |
| 227 | 218 | ||
| 228 | static int uio_pdrv_genirq_remove(struct platform_device *pdev) | 219 | 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 | priv->uioinfo->handler = NULL; | 226 | priv->uioinfo->handler = NULL; |
| 236 | priv->uioinfo->irqcontrol = NULL; | 227 | priv->uioinfo->irqcontrol = NULL; |
| 237 | 228 | ||
| 238 | /* kfree uioinfo for OF */ | ||
| 239 | if (pdev->dev.of_node) | ||
| 240 | kfree(priv->uioinfo); | ||
| 241 | |||
| 242 | kfree(priv); | ||
| 243 | return 0; | 229 | return 0; |
| 244 | } | 230 | } |
| 245 | 231 | ||
