* [PATCH 1/3] spi: fsl-(e)spi: migrate to using devm_ functions to simplify cleanup
@ 2015-08-23 12:20 Heiner Kallweit
[not found] ` <55D9BAAA.7060401-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Heiner Kallweit @ 2015-08-23 12:20 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA
Migrate fsl-espi and fsl-spi to using the managed devm_ functions
for resource handling. This simplifies the cleanup.
Signed-off-by: Heiner Kallweit <hkallweit1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/spi/spi-fsl-espi.c | 16 ++++++----------
drivers/spi/spi-fsl-lib.c | 4 ----
drivers/spi/spi-fsl-spi.c | 22 +++++++++-------------
3 files changed, 15 insertions(+), 27 deletions(-)
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index d3f05a0..bfd6259 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -606,7 +606,6 @@ static irqreturn_t fsl_espi_irq(s32 irq, void *context_data)
static void fsl_espi_remove(struct mpc8xxx_spi *mspi)
{
- iounmap(mspi->reg_base);
}
static int fsl_espi_suspend(struct spi_master *master)
@@ -673,7 +672,8 @@ static struct spi_master * fsl_espi_probe(struct device *dev,
mpc8xxx_spi = spi_master_get_devdata(master);
mpc8xxx_spi->spi_remove = fsl_espi_remove;
- mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
+ mpc8xxx_spi->reg_base = devm_ioremap(dev, mem->start,
+ resource_size(mem));
if (!mpc8xxx_spi->reg_base) {
ret = -ENOMEM;
goto err_probe;
@@ -682,10 +682,10 @@ static struct spi_master * fsl_espi_probe(struct device *dev,
reg_base = mpc8xxx_spi->reg_base;
/* Register for SPI Interrupt */
- ret = request_irq(mpc8xxx_spi->irq, fsl_espi_irq,
+ ret = devm_request_irq(dev, mpc8xxx_spi->irq, fsl_espi_irq,
0, "fsl_espi", mpc8xxx_spi);
if (ret)
- goto free_irq;
+ goto err_probe;
if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
mpc8xxx_spi->rx_shift = 16;
@@ -731,18 +731,14 @@ static struct spi_master * fsl_espi_probe(struct device *dev,
mpc8xxx_spi_write_reg(®_base->mode, regval);
- ret = spi_register_master(master);
+ ret = devm_spi_register_master(dev, master);
if (ret < 0)
- goto unreg_master;
+ goto err_probe;
dev_info(dev, "at 0x%p (irq = %d)\n", reg_base, mpc8xxx_spi->irq);
return master;
-unreg_master:
- free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
-free_irq:
- iounmap(mpc8xxx_spi->reg_base);
err_probe:
spi_master_put(master);
err:
diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c
index cb35d2f..e50fd06 100644
--- a/drivers/spi/spi-fsl-lib.c
+++ b/drivers/spi/spi-fsl-lib.c
@@ -122,10 +122,6 @@ int mpc8xxx_spi_remove(struct device *dev)
master = dev_get_drvdata(dev);
mpc8xxx_spi = spi_master_get_devdata(master);
- spi_unregister_master(master);
-
- free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
-
if (mpc8xxx_spi->spi_remove)
mpc8xxx_spi->spi_remove(mpc8xxx_spi);
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
index 60c5907..fbbab60 100644
--- a/drivers/spi/spi-fsl-spi.c
+++ b/drivers/spi/spi-fsl-spi.c
@@ -561,7 +561,6 @@ static irqreturn_t fsl_spi_irq(s32 irq, void *context_data)
static void fsl_spi_remove(struct mpc8xxx_spi *mspi)
{
- iounmap(mspi->reg_base);
fsl_spi_cpm_free(mspi);
}
@@ -639,10 +638,11 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
if (ret)
goto err_cpm_init;
- mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
+ mpc8xxx_spi->reg_base = devm_ioremap(dev, mem->start,
+ resource_size(mem));
if (mpc8xxx_spi->reg_base == NULL) {
ret = -ENOMEM;
- goto err_ioremap;
+ goto err_probe;
}
if (mpc8xxx_spi->type == TYPE_GRLIB)
@@ -661,11 +661,11 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
&mpc8xxx_spi->tx_shift, 8, 1);
/* Register for SPI Interrupt */
- ret = request_irq(mpc8xxx_spi->irq, fsl_spi_irq,
- 0, "fsl_spi", mpc8xxx_spi);
+ ret = devm_request_irq(dev, mpc8xxx_spi->irq, fsl_spi_irq,
+ 0, "fsl_spi", mpc8xxx_spi);
if (ret != 0)
- goto free_irq;
+ goto err_probe;
reg_base = mpc8xxx_spi->reg_base;
@@ -686,20 +686,16 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
mpc8xxx_spi_write_reg(®_base->mode, regval);
- ret = spi_register_master(master);
+ ret = devm_spi_register_master(dev, master);
if (ret < 0)
- goto unreg_master;
+ goto err_probe;
dev_info(dev, "at 0x%p (irq = %d), %s mode\n", reg_base,
mpc8xxx_spi->irq, mpc8xxx_spi_strmode(mpc8xxx_spi->flags));
return master;
-unreg_master:
- free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
-free_irq:
- iounmap(mpc8xxx_spi->reg_base);
-err_ioremap:
+err_probe:
fsl_spi_cpm_free(mpc8xxx_spi);
err_cpm_init:
spi_master_put(master);
--
2.5.0
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] spi: fsl-(e)spi: migrate to using devm_ functions to simplify cleanup
[not found] ` <55D9BAAA.7060401-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-08-25 17:26 ` Mark Brown
[not found] ` <20150825172644.GD12878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-25 17:43 ` Mark Brown
1 sibling, 1 reply; 5+ messages in thread
From: Mark Brown @ 2015-08-25 17:26 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 305 bytes --]
On Sun, Aug 23, 2015 at 02:20:58PM +0200, Heiner Kallweit wrote:
> - mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
> + mpc8xxx_spi->reg_base = devm_ioremap(dev, mem->start,
> + resource_size(mem));
What would be even nicer here would be to convert to devm_ioremap_resource()
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] spi: fsl-(e)spi: migrate to using devm_ functions to simplify cleanup
[not found] ` <55D9BAAA.7060401-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-08-25 17:26 ` Mark Brown
@ 2015-08-25 17:43 ` Mark Brown
[not found] ` <20150825174349.GE12878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
1 sibling, 1 reply; 5+ messages in thread
From: Mark Brown @ 2015-08-25 17:43 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 453 bytes --]
On Sun, Aug 23, 2015 at 02:20:58PM +0200, Heiner Kallweit wrote:
> /* Register for SPI Interrupt */
> - ret = request_irq(mpc8xxx_spi->irq, fsl_espi_irq,
> + ret = devm_request_irq(dev, mpc8xxx_spi->irq, fsl_espi_irq,
> 0, "fsl_espi", mpc8xxx_spi);
Also, are you *sure* this conversion is safe? One trick with interrupts
is that the interrupt could still fire after the device removal function
runs since devm_ dealloacation runs after that.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] spi: fsl-(e)spi: migrate to using devm_ functions to simplify cleanup
[not found] ` <20150825172644.GD12878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2015-08-25 19:54 ` Heiner Kallweit
0 siblings, 0 replies; 5+ messages in thread
From: Heiner Kallweit @ 2015-08-25 19:54 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA
Am 25.08.2015 um 19:26 schrieb Mark Brown:
> On Sun, Aug 23, 2015 at 02:20:58PM +0200, Heiner Kallweit wrote:
>
>> - mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
>> + mpc8xxx_spi->reg_base = devm_ioremap(dev, mem->start,
>> + resource_size(mem));
>
> What would be even nicer here would be to convert to devm_ioremap_resource()
Thanks for the hint, I'll check.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] spi: fsl-(e)spi: migrate to using devm_ functions to simplify cleanup
[not found] ` <20150825174349.GE12878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2015-08-25 20:14 ` Heiner Kallweit
0 siblings, 0 replies; 5+ messages in thread
From: Heiner Kallweit @ 2015-08-25 20:14 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA
Am 25.08.2015 um 19:43 schrieb Mark Brown:
> On Sun, Aug 23, 2015 at 02:20:58PM +0200, Heiner Kallweit wrote:
>
>> /* Register for SPI Interrupt */
>> - ret = request_irq(mpc8xxx_spi->irq, fsl_espi_irq,
>> + ret = devm_request_irq(dev, mpc8xxx_spi->irq, fsl_espi_irq,
>> 0, "fsl_espi", mpc8xxx_spi);
>
> Also, are you *sure* this conversion is safe? One trick with interrupts
> is that the interrupt could still fire after the device removal function
> runs since devm_ dealloacation runs after that.
After each transfer interrupts are disabled (at end of fsl_espi_bufs).
Therefore I *think* it's safe.
And as resources are freed in reverse order (irq first), shouldn't this be enough
to be on the safe side?
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-08-25 20:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-23 12:20 [PATCH 1/3] spi: fsl-(e)spi: migrate to using devm_ functions to simplify cleanup Heiner Kallweit
[not found] ` <55D9BAAA.7060401-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-08-25 17:26 ` Mark Brown
[not found] ` <20150825172644.GD12878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-25 19:54 ` Heiner Kallweit
2015-08-25 17:43 ` Mark Brown
[not found] ` <20150825174349.GE12878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-25 20:14 ` Heiner Kallweit
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).