Commit ba0a7f39 authored by Atsushi Nemoto's avatar Atsushi Nemoto Committed by Linus Torvalds

spi: fix error paths on txx9spi_probe

Some error paths in txx9spi_probe wrongly return 0.  This patch fixes them by
using the devres interfaces.
Signed-off-by: default avatarAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Acked-by: default avatarDavid Brownell <david-b@pacbell.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 350d0076
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/io.h>
#include <asm/gpio.h> #include <asm/gpio.h>
...@@ -74,7 +75,6 @@ struct txx9spi { ...@@ -74,7 +75,6 @@ struct txx9spi {
struct list_head queue; struct list_head queue;
wait_queue_head_t waitq; wait_queue_head_t waitq;
void __iomem *membase; void __iomem *membase;
int irq;
int baseclk; int baseclk;
struct clk *clk; struct clk *clk;
u32 max_speed_hz, min_speed_hz; u32 max_speed_hz, min_speed_hz;
...@@ -350,12 +350,12 @@ static int __init txx9spi_probe(struct platform_device *dev) ...@@ -350,12 +350,12 @@ static int __init txx9spi_probe(struct platform_device *dev)
struct resource *res; struct resource *res;
int ret = -ENODEV; int ret = -ENODEV;
u32 mcr; u32 mcr;
int irq;
master = spi_alloc_master(&dev->dev, sizeof(*c)); master = spi_alloc_master(&dev->dev, sizeof(*c));
if (!master) if (!master)
return ret; return ret;
c = spi_master_get_devdata(master); c = spi_master_get_devdata(master);
c->irq = -1;
platform_set_drvdata(dev, master); platform_set_drvdata(dev, master);
INIT_WORK(&c->work, txx9spi_work); INIT_WORK(&c->work, txx9spi_work);
...@@ -381,32 +381,36 @@ static int __init txx9spi_probe(struct platform_device *dev) ...@@ -381,32 +381,36 @@ static int __init txx9spi_probe(struct platform_device *dev)
res = platform_get_resource(dev, IORESOURCE_MEM, 0); res = platform_get_resource(dev, IORESOURCE_MEM, 0);
if (!res) if (!res)
goto exit; goto exit_busy;
c->membase = ioremap(res->start, res->end - res->start + 1); if (!devm_request_mem_region(&dev->dev,
res->start, res->end - res->start + 1,
"spi_txx9"))
goto exit_busy;
c->membase = devm_ioremap(&dev->dev,
res->start, res->end - res->start + 1);
if (!c->membase) if (!c->membase)
goto exit; goto exit_busy;
/* enter config mode */ /* enter config mode */
mcr = txx9spi_rd(c, TXx9_SPMCR); mcr = txx9spi_rd(c, TXx9_SPMCR);
mcr &= ~(TXx9_SPMCR_OPMODE | TXx9_SPMCR_SPSTP | TXx9_SPMCR_BCLR); mcr &= ~(TXx9_SPMCR_OPMODE | TXx9_SPMCR_SPSTP | TXx9_SPMCR_BCLR);
txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, TXx9_SPMCR); txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, TXx9_SPMCR);
c->irq = platform_get_irq(dev, 0); irq = platform_get_irq(dev, 0);
if (c->irq < 0) if (irq < 0)
goto exit; goto exit_busy;
ret = request_irq(c->irq, txx9spi_interrupt, 0, dev->name, c); ret = devm_request_irq(&dev->dev, irq, txx9spi_interrupt, 0,
if (ret) { "spi_txx9", c);
c->irq = -1; if (ret)
goto exit; goto exit;
}
c->workqueue = create_singlethread_workqueue(master->dev.parent->bus_id); c->workqueue = create_singlethread_workqueue(master->dev.parent->bus_id);
if (!c->workqueue) if (!c->workqueue)
goto exit; goto exit_busy;
c->last_chipselect = -1; c->last_chipselect = -1;
dev_info(&dev->dev, "at %#llx, irq %d, %dMHz\n", dev_info(&dev->dev, "at %#llx, irq %d, %dMHz\n",
(unsigned long long)res->start, c->irq, (unsigned long long)res->start, irq,
(c->baseclk + 500000) / 1000000); (c->baseclk + 500000) / 1000000);
master->bus_num = dev->id; master->bus_num = dev->id;
...@@ -418,13 +422,11 @@ static int __init txx9spi_probe(struct platform_device *dev) ...@@ -418,13 +422,11 @@ static int __init txx9spi_probe(struct platform_device *dev)
if (ret) if (ret)
goto exit; goto exit;
return 0; return 0;
exit_busy:
ret = -EBUSY;
exit: exit:
if (c->workqueue) if (c->workqueue)
destroy_workqueue(c->workqueue); destroy_workqueue(c->workqueue);
if (c->irq >= 0)
free_irq(c->irq, c);
if (c->membase)
iounmap(c->membase);
if (c->clk) { if (c->clk) {
clk_disable(c->clk); clk_disable(c->clk);
clk_put(c->clk); clk_put(c->clk);
...@@ -442,8 +444,6 @@ static int __exit txx9spi_remove(struct platform_device *dev) ...@@ -442,8 +444,6 @@ static int __exit txx9spi_remove(struct platform_device *dev)
spi_unregister_master(master); spi_unregister_master(master);
platform_set_drvdata(dev, NULL); platform_set_drvdata(dev, NULL);
destroy_workqueue(c->workqueue); destroy_workqueue(c->workqueue);
free_irq(c->irq, c);
iounmap(c->membase);
clk_disable(c->clk); clk_disable(c->clk);
clk_put(c->clk); clk_put(c->clk);
spi_master_put(master); spi_master_put(master);
......
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