@@ -114,29 +114,27 @@ static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
static int sh_sci_spi_probe(struct platform_device *dev)
{
struct resource *r;
- struct spi_master *master;
+ struct spi_controller *ctlr;
struct sh_sci_spi *sp;
int ret;
- master = spi_alloc_master(&dev->dev, sizeof(struct sh_sci_spi));
- if (master == NULL) {
- dev_err(&dev->dev, "failed to allocate spi master\n");
- ret = -ENOMEM;
- goto err0;
+ ctlr = __devm_spi_alloc_controller(&dev->dev, sizeof(*sp), false);
+ if (!ctlr) {
+ dev_err(&dev->dev, "failed to allocate spi controller\n");
+ return -ENOMEM;
}
- sp = spi_master_get_devdata(master);
+ sp = spi_controller_get_devdata(ctlr);
platform_set_drvdata(dev, sp);
sp->info = dev_get_platdata(&dev->dev);
if (!sp->info) {
dev_err(&dev->dev, "platform data is missing\n");
- ret = -ENOENT;
- goto err1;
+ return -ENOENT;
}
/* setup spi bitbang adaptor */
- sp->bitbang.master = master;
+ sp->bitbang.master = ctlr;
sp->bitbang.master->bus_num = sp->info->bus_num;
sp->bitbang.master->num_chipselect = sp->info->num_chipselect;
sp->bitbang.chipselect = sh_sci_spi_chipselect;
@@ -147,28 +145,22 @@ static int sh_sci_spi_probe(struct platform_device *dev)
sp->bitbang.txrx_word[SPI_MODE_3] = sh_sci_spi_txrx_mode3;
r = platform_get_resource(dev, IORESOURCE_MEM, 0);
- if (r == NULL) {
- ret = -ENOENT;
- goto err1;
- }
+ if (r == NULL)
+ return -ENOENT;
sp->membase = ioremap(r->start, resource_size(r));
- if (!sp->membase) {
- ret = -ENXIO;
- goto err1;
- }
+ if (!sp->membase)
+ return -ENXIO;
sp->val = ioread8(SCSPTR(sp));
setbits(sp, PIN_INIT, 1);
ret = spi_bitbang_start(&sp->bitbang);
- if (!ret)
- return 0;
+ if (ret) {
+ setbits(sp, PIN_INIT, 0);
+ iounmap(sp->membase);
+ return ret;
+ }
- setbits(sp, PIN_INIT, 0);
- iounmap(sp->membase);
- err1:
- spi_master_put(sp->bitbang.master);
- err0:
- return ret;
+ return 0;
}
static int sh_sci_spi_remove(struct platform_device *dev)
With using __devm_spi_alloc_controller(), spi_controller_put() is called in devres_release_all() whenever the device is unbound, so the spi_master_put() in error path can be removed. Also replace spi_master_get_devdata() with spi_controller_get_devdata(). Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- drivers/spi/spi-sh-sci.c | 44 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 26 deletions(-)