UIO: fix uio_pdrv_genirq with device tree but no interrupt

If device is initialized from device tree, but has no interrupt
assigned, uio will still try to request and interrupt old way,
fails, and fails registration.

This is wrong; don't try initializing irq using platform data if
device tree is available.

Simplified code based on suggestion by Grant Likely.

Fixed memory leak in "irq can not be registered" error path.

Signed-off-by: Pavel Machek <pavel@denx.de>
Reported-by: Detlev Zundel <dzu@denx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Pavel Machek 2013-06-18 22:34:53 +02:00 committed by Greg Kroah-Hartman
parent 05c3e0bb56
commit e3a3c3a205

View File

@ -103,24 +103,16 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)
int i; int i;
if (pdev->dev.of_node) { if (pdev->dev.of_node) {
int irq;
/* alloc uioinfo for one device */ /* alloc uioinfo for one device */
uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL); uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL);
if (!uioinfo) { if (!uioinfo) {
ret = -ENOMEM; ret = -ENOMEM;
dev_err(&pdev->dev, "unable to kmalloc\n"); dev_err(&pdev->dev, "unable to kmalloc\n");
goto bad2; return ret;
} }
uioinfo->name = pdev->dev.of_node->name; uioinfo->name = pdev->dev.of_node->name;
uioinfo->version = "devicetree"; uioinfo->version = "devicetree";
/* Multiple IRQs are not supported */ /* Multiple IRQs are not supported */
irq = platform_get_irq(pdev, 0);
if (irq == -ENXIO)
uioinfo->irq = UIO_IRQ_NONE;
else
uioinfo->irq = irq;
} }
if (!uioinfo || !uioinfo->name || !uioinfo->version) { if (!uioinfo || !uioinfo->name || !uioinfo->version) {
@ -148,12 +140,15 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)
if (!uioinfo->irq) { if (!uioinfo->irq) {
ret = platform_get_irq(pdev, 0); ret = platform_get_irq(pdev, 0);
if (ret < 0) {
dev_err(&pdev->dev, "failed to get IRQ\n");
goto bad0;
}
uioinfo->irq = ret; uioinfo->irq = ret;
if (ret == -ENXIO && pdev->dev.of_node)
uioinfo->irq = UIO_IRQ_NONE;
else if (ret < 0) {
dev_err(&pdev->dev, "failed to get IRQ\n");
goto bad1;
}
} }
uiomem = &uioinfo->mem[0]; uiomem = &uioinfo->mem[0];
for (i = 0; i < pdev->num_resources; ++i) { for (i = 0; i < pdev->num_resources; ++i) {
@ -206,19 +201,19 @@ 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 bad1; goto bad2;
} }
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
return 0; return 0;
bad2:
pm_runtime_disable(&pdev->dev);
bad1: bad1:
kfree(priv); kfree(priv);
pm_runtime_disable(&pdev->dev);
bad0: bad0:
/* kfree uioinfo for OF */ /* kfree uioinfo for OF */
if (pdev->dev.of_node) if (pdev->dev.of_node)
kfree(uioinfo); kfree(uioinfo);
bad2:
return ret; return ret;
} }