* [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR()
@ 2013-01-10 20:29 Andrew Lunn
2013-01-10 20:49 ` Jason Cooper
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Andrew Lunn @ 2013-01-10 20:29 UTC (permalink / raw)
To: linux-arm-kernel
A NULL is a valid clk cookie, so we should not be tested with
IS_ERR_NULL(). Replace it with IS_ERR().
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/mmc/host/mvsdio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index de4c20b..d0050fa 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -839,7 +839,7 @@ out:
if (r)
release_resource(r);
if (mmc)
- if (!IS_ERR_OR_NULL(host->clk)) {
+ if (!IS_ERR(host->clk)) {
clk_disable_unprepare(host->clk);
clk_put(host->clk);
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR()
2013-01-10 20:29 [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR() Andrew Lunn
@ 2013-01-10 20:49 ` Jason Cooper
2013-01-11 0:43 ` Simon Baatz
2013-01-11 11:02 ` [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is " Russell King - ARM Linux
2 siblings, 0 replies; 9+ messages in thread
From: Jason Cooper @ 2013-01-10 20:49 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Jan 10, 2013 at 09:29:15PM +0100, Andrew Lunn wrote:
> A NULL is a valid clk cookie, so we should not be tested with
> IS_ERR_NULL(). Replace it with IS_ERR().
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
> drivers/mmc/host/mvsdio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
The subject and commit entry should be IS_ERR_OR_NULL, but other than
that:
Acked-by: Jason Cooper <jason@lakedaemon.net>
thx,
Jason.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR()
2013-01-10 20:29 [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR() Andrew Lunn
2013-01-10 20:49 ` Jason Cooper
@ 2013-01-11 0:43 ` Simon Baatz
2013-01-11 7:27 ` [PATCH v2] mmc: mvsdio: Replace IS_ERR_OR_NULL() " Andrew Lunn
2013-01-11 11:02 ` [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is " Russell King - ARM Linux
2 siblings, 1 reply; 9+ messages in thread
From: Simon Baatz @ 2013-01-11 0:43 UTC (permalink / raw)
To: linux-arm-kernel
Hi Andrew,
On Thu, Jan 10, 2013 at 09:29:15PM +0100, Andrew Lunn wrote:
> A NULL is a valid clk cookie, so we should not be tested with
> IS_ERR_NULL(). Replace it with IS_ERR().
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
> drivers/mmc/host/mvsdio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
> index de4c20b..d0050fa 100644
> --- a/drivers/mmc/host/mvsdio.c
> +++ b/drivers/mmc/host/mvsdio.c
> @@ -839,7 +839,7 @@ out:
> if (r)
> release_resource(r);
> if (mmc)
> - if (!IS_ERR_OR_NULL(host->clk)) {
> + if (!IS_ERR(host->clk)) {
> clk_disable_unprepare(host->clk);
> clk_put(host->clk);
> }
Hmm. I think this check was originally intended to go under "if
(host)" above and not here. Notice the indentation mismatch/missing
braces for "if (mmc)". My bad.
Additionally, host->clk == NULL is not necessarily the result of
clk_get() but it can also be NULL if the irq could not be assigned.
Leading to unbalanced clk calls in this case.
- Simon
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] mmc: mvsdio: Replace IS_ERR_OR_NULL() with IS_ERR()
2013-01-11 0:43 ` Simon Baatz
@ 2013-01-11 7:27 ` Andrew Lunn
2013-01-13 20:43 ` Jason Cooper
0 siblings, 1 reply; 9+ messages in thread
From: Andrew Lunn @ 2013-01-11 7:27 UTC (permalink / raw)
To: linux-arm-kernel
A NULL is a valid clk cookie, so we should not be tested with
IS_ERR_OR_NULL(). Replace it with IS_ERR().
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
This patch depends on Thomas Petazzoni DT patches for mvsdio, which changed
the order of resource allocation etc.
Simon
You are correct about the indentation. As suggested, i moved the
disable_unprepare() inside if (host).
It should no longer be possible to have imbalanced clk operations:
If mmc_alloc_host() fails, it goes to out. host is NULL, no clk calls.
All other goto out occur after the clk_get() and when host is !NULL. clk
calls are then made when !IS_ERR(host->clk), keeping this balanced.
drivers/mmc/host/mvsdio.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index feb16bd..196f085 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -818,14 +818,14 @@ out:
mmc_gpio_free_ro(mmc);
if (host->base)
iounmap(host->base);
+ if (!IS_ERR(host->clk)) {
+ clk_disable_unprepare(host->clk);
+ clk_put(host->clk);
+ }
}
if (r)
release_resource(r);
if (mmc)
- if (!IS_ERR_OR_NULL(host->clk)) {
- clk_disable_unprepare(host->clk);
- clk_put(host->clk);
- }
mmc_free_host(mmc);
return ret;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR()
2013-01-10 20:29 [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR() Andrew Lunn
2013-01-10 20:49 ` Jason Cooper
2013-01-11 0:43 ` Simon Baatz
@ 2013-01-11 11:02 ` Russell King - ARM Linux
2013-01-11 11:09 ` Thomas Petazzoni
2 siblings, 1 reply; 9+ messages in thread
From: Russell King - ARM Linux @ 2013-01-11 11:02 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Jan 10, 2013 at 09:29:15PM +0100, Andrew Lunn wrote:
> A NULL is a valid clk cookie, so we should not be tested with
> IS_ERR_NULL(). Replace it with IS_ERR().
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
> drivers/mmc/host/mvsdio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
> index de4c20b..d0050fa 100644
> --- a/drivers/mmc/host/mvsdio.c
> +++ b/drivers/mmc/host/mvsdio.c
> @@ -839,7 +839,7 @@ out:
> if (r)
> release_resource(r);
> if (mmc)
> - if (!IS_ERR_OR_NULL(host->clk)) {
> + if (!IS_ERR(host->clk)) {
> clk_disable_unprepare(host->clk);
> clk_put(host->clk);
> }
Actually, no.
1. I've already recently pointed out that C is not python, and this code
is broken. (Look at the lack of missing braces around the code you've
modified.)
2. host->clk _can_ be NULL here.
Here's the (untested) bare minimum needed to fix this driver:
drivers/mmc/host/mvsdio.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index de4c20b..4190fb4 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -733,6 +733,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
host->dev = &pdev->dev;
host->res = r;
host->base_clock = mvsd_data->clock / 2;
+ host->clk = ERR_PTR(-EINVAL);
mmc->ops = &mvsd_ops;
@@ -837,13 +838,14 @@ static int __init mvsd_probe(struct platform_device *pdev)
iounmap(host->base);
}
if (r)
- release_resource(r);
- if (mmc)
- if (!IS_ERR_OR_NULL(host->clk)) {
+ release_mem_resource(r->start, resource_size(r));
+ if (mmc) {
+ if (!IS_ERR(host->clk)) {
clk_disable_unprepare(host->clk);
clk_put(host->clk);
}
mmc_free_host(mmc);
+ }
return ret;
}
@@ -866,7 +868,7 @@ static int __exit mvsd_remove(struct platform_device *pdev)
del_timer_sync(&host->timer);
mvsd_power_down(host);
iounmap(host->base);
- release_resource(host->res);
+ release_mem_resource(host->res->start, resource_size(host->res);
if (!IS_ERR(host->clk)) {
clk_disable_unprepare(host->clk);
But... we can do better than that. We have the devm_* APIs which will
make this code simpler, and less prone to these kinds of silly errors.
I've left the request_irq()s alone because it isn't obvious to me that
there isn't a reason for releasing the IRQ at a particular point in the
cleanup, and there's no sign that IRQs may be asked on the device itself.
Note also that I found another bug in this driver - it requests a region
1K in size, but ioremaps 4K. That's just wrong. But anyway, the whole
issue goes away with devm_request_and_ioremap().
What remains? The assumption that GPIO0 means "no GPIO" rather than
testing with gpio_valid() and the IRQ stuff.
drivers/mmc/host/mvsdio.c | 61 +++++++++++++++-----------------------------
1 files changed, 21 insertions(+), 40 deletions(-)
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index de4c20b..4723310 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -50,7 +50,6 @@ struct mvsd_host {
struct timer_list timer;
struct mmc_host *mmc;
struct device *dev;
- struct resource *res;
int irq;
struct clk *clk;
int gpio_card_detect;
@@ -718,10 +717,6 @@ static int __init mvsd_probe(struct platform_device *pdev)
if (!r || irq < 0 || !mvsd_data)
return -ENXIO;
- r = request_mem_region(r->start, SZ_1K, DRIVER_NAME);
- if (!r)
- return -EBUSY;
-
mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
if (!mmc) {
ret = -ENOMEM;
@@ -731,8 +726,8 @@ static int __init mvsd_probe(struct platform_device *pdev)
host = mmc_priv(mmc);
host->mmc = mmc;
host->dev = &pdev->dev;
- host->res = r;
host->base_clock = mvsd_data->clock / 2;
+ host->clk = ERR_PTR(-EINVAL);
mmc->ops = &mvsd_ops;
@@ -752,7 +747,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
spin_lock_init(&host->lock);
- host->base = ioremap(r->start, SZ_4K);
+ host->base = devm_request_and_ioremap(&pdev->dev, r);
if (!host->base) {
ret = -ENOMEM;
goto out;
@@ -774,16 +769,15 @@ static int __init mvsd_probe(struct platform_device *pdev)
/* Not all platforms can gate the clock, so it is not
an error if the clock does not exists. */
- host->clk = clk_get(&pdev->dev, NULL);
- if (!IS_ERR(host->clk)) {
+ host->clk = devm_clk_get(&pdev->dev, NULL);
+ if (!IS_ERR(host->clk))
clk_prepare_enable(host->clk);
- }
if (mvsd_data->gpio_card_detect) {
- ret = gpio_request(mvsd_data->gpio_card_detect,
- DRIVER_NAME " cd");
+ ret = devm_gpio_request_one(&pdev->dev,
+ mvsd_data->gpio_card_detect,
+ GPIOF_IN, DRIVER_NAME " cd");
if (ret == 0) {
- gpio_direction_input(mvsd_data->gpio_card_detect);
irq = gpio_to_irq(mvsd_data->gpio_card_detect);
ret = request_irq(irq, mvsd_card_detect_irq,
IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
@@ -792,17 +786,18 @@ static int __init mvsd_probe(struct platform_device *pdev)
host->gpio_card_detect =
mvsd_data->gpio_card_detect;
else
- gpio_free(mvsd_data->gpio_card_detect);
+ devm_gpio_free(&pdev->dev,
+ mvsd_data->gpio_card_detect);
}
}
if (!host->gpio_card_detect)
mmc->caps |= MMC_CAP_NEEDS_POLL;
if (mvsd_data->gpio_write_protect) {
- ret = gpio_request(mvsd_data->gpio_write_protect,
- DRIVER_NAME " wp");
+ ret = devm_gpio_request_one(&pdev->dev,
+ mvsd_data->gpio_write_protect,
+ GPIOF_IN, DRIVER_NAME " wp");
if (ret == 0) {
- gpio_direction_input(mvsd_data->gpio_write_protect);
host->gpio_write_protect =
mvsd_data->gpio_write_protect;
}
@@ -827,23 +822,15 @@ static int __init mvsd_probe(struct platform_device *pdev)
if (host) {
if (host->irq)
free_irq(host->irq, host);
- if (host->gpio_card_detect) {
+ if (host->gpio_card_detect)
free_irq(gpio_to_irq(host->gpio_card_detect), host);
- gpio_free(host->gpio_card_detect);
- }
- if (host->gpio_write_protect)
- gpio_free(host->gpio_write_protect);
- if (host->base)
- iounmap(host->base);
}
- if (r)
- release_resource(r);
- if (mmc)
- if (!IS_ERR_OR_NULL(host->clk)) {
+ if (mmc) {
+ if (!IS_ERR(host->clk))
clk_disable_unprepare(host->clk);
- clk_put(host->clk);
- }
+
mmc_free_host(mmc);
+ }
return ret;
}
@@ -855,23 +842,17 @@ static int __exit mvsd_remove(struct platform_device *pdev)
if (mmc) {
struct mvsd_host *host = mmc_priv(mmc);
- if (host->gpio_card_detect) {
+ if (host->gpio_card_detect)
free_irq(gpio_to_irq(host->gpio_card_detect), host);
- gpio_free(host->gpio_card_detect);
- }
+
mmc_remove_host(mmc);
free_irq(host->irq, host);
- if (host->gpio_write_protect)
- gpio_free(host->gpio_write_protect);
del_timer_sync(&host->timer);
mvsd_power_down(host);
- iounmap(host->base);
- release_resource(host->res);
- if (!IS_ERR(host->clk)) {
+ if (!IS_ERR(host->clk))
clk_disable_unprepare(host->clk);
- clk_put(host->clk);
- }
+
mmc_free_host(mmc);
}
platform_set_drvdata(pdev, NULL);
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR()
2013-01-11 11:02 ` [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is " Russell King - ARM Linux
@ 2013-01-11 11:09 ` Thomas Petazzoni
2013-01-11 11:11 ` Russell King - ARM Linux
0 siblings, 1 reply; 9+ messages in thread
From: Thomas Petazzoni @ 2013-01-11 11:09 UTC (permalink / raw)
To: linux-arm-kernel
Dear Russell King - ARM Linux,
On Fri, 11 Jan 2013 11:02:10 +0000, Russell King - ARM Linux wrote:
> What remains? The assumption that GPIO0 means "no GPIO" rather than
> testing with gpio_valid() and the IRQ stuff.
Patches that I have written have been merged by Jason Cooper and while
adding the DT binding for this driver, it also converts it to use the
MMC GPIO helpers from drivers/mmc/core/slot-gpio.c, which makes this
whole GPIO initialization/cleanup a lot simpler.
See:
http://git.infradead.org/users/jcooper/linux.git/commitdiff/c3833fbb117bb1a547d29b27a0de4418fa2d5a5a
http://git.infradead.org/users/jcooper/linux.git/commitdiff/e60a21ed4edb7f33010ab21cefcb20666a9bc7d7
Also, note that Andrew Lunn has sent a v2 of his patch:
Subject: [PATCH v2] mmc: mvsdio: Replace IS_ERR_OR_NULL() with IS_ERR()
Date: Fri, 11 Jan 2013 08:27:52 +0100
Best regards,
Thomas
--
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR()
2013-01-11 11:09 ` Thomas Petazzoni
@ 2013-01-11 11:11 ` Russell King - ARM Linux
0 siblings, 0 replies; 9+ messages in thread
From: Russell King - ARM Linux @ 2013-01-11 11:11 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 11, 2013 at 12:09:09PM +0100, Thomas Petazzoni wrote:
> Dear Russell King - ARM Linux,
>
> On Fri, 11 Jan 2013 11:02:10 +0000, Russell King - ARM Linux wrote:
>
> > What remains? The assumption that GPIO0 means "no GPIO" rather than
> > testing with gpio_valid() and the IRQ stuff.
>
> Patches that I have written have been merged by Jason Cooper and while
> adding the DT binding for this driver, it also converts it to use the
> MMC GPIO helpers from drivers/mmc/core/slot-gpio.c, which makes this
> whole GPIO initialization/cleanup a lot simpler.
Please also fix the whole raft of other crap in this driver too, as
I've highlighted previously and in these patches.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] mmc: mvsdio: Replace IS_ERR_OR_NULL() with IS_ERR()
2013-01-11 7:27 ` [PATCH v2] mmc: mvsdio: Replace IS_ERR_OR_NULL() " Andrew Lunn
@ 2013-01-13 20:43 ` Jason Cooper
2013-01-13 21:42 ` Andrew Lunn
0 siblings, 1 reply; 9+ messages in thread
From: Jason Cooper @ 2013-01-13 20:43 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 11, 2013 at 08:27:52AM +0100, Andrew Lunn wrote:
> A NULL is a valid clk cookie, so we should not be tested with
> IS_ERR_OR_NULL(). Replace it with IS_ERR().
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>
> This patch depends on Thomas Petazzoni DT patches for mvsdio, which changed
> the order of resource allocation etc.
grrr, I'm seeing fixes depending on features :( Any way to avoid that?
In light of Russell's comments, shall I wait for a v3? All of Thomas'
mvsdio work is now waiting on this. I'd like to get that in as early as
possible.
thx,
Jason.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] mmc: mvsdio: Replace IS_ERR_OR_NULL() with IS_ERR()
2013-01-13 20:43 ` Jason Cooper
@ 2013-01-13 21:42 ` Andrew Lunn
0 siblings, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2013-01-13 21:42 UTC (permalink / raw)
To: linux-arm-kernel
On Sun, Jan 13, 2013 at 03:43:48PM -0500, Jason Cooper wrote:
> On Fri, Jan 11, 2013 at 08:27:52AM +0100, Andrew Lunn wrote:
> > A NULL is a valid clk cookie, so we should not be tested with
> > IS_ERR_OR_NULL(). Replace it with IS_ERR().
> >
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> >
> > This patch depends on Thomas Petazzoni DT patches for mvsdio, which changed
> > the order of resource allocation etc.
>
> grrr, I'm seeing fixes depending on features :( Any way to avoid that?
>
> In light of Russell's comments, shall I wait for a v3? All of Thomas'
> mvsdio work is now waiting on this. I'd like to get that in as early as
> possible.
Well, im guessing doing the fixes first will require changes to Thomas
features.
Did you try putting Russells patch in first? How bad are the
conflicts?
Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-01-13 21:42 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-10 20:29 [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is with IS_ERR() Andrew Lunn
2013-01-10 20:49 ` Jason Cooper
2013-01-11 0:43 ` Simon Baatz
2013-01-11 7:27 ` [PATCH v2] mmc: mvsdio: Replace IS_ERR_OR_NULL() " Andrew Lunn
2013-01-13 20:43 ` Jason Cooper
2013-01-13 21:42 ` Andrew Lunn
2013-01-11 11:02 ` [PATCH] mmc: mvsdio: Replace IS_ERR_NULL() is " Russell King - ARM Linux
2013-01-11 11:09 ` Thomas Petazzoni
2013-01-11 11:11 ` Russell King - ARM Linux
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).