linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: i2c-ocores: Use devm_request_and_ioremap()
@ 2012-08-08  6:54 Thierry Reding
       [not found] ` <1344408872-1051-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
  2012-11-13 11:19 ` Wolfram Sang
  0 siblings, 2 replies; 5+ messages in thread
From: Thierry Reding @ 2012-08-08  6:54 UTC (permalink / raw)
  To: Peter Korsgaard
  Cc: Jean Delvare (PC drivers, core), Ben Dooks (embedded platforms),
	Wolfram Sang (embedded platforms),
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Replacing the devm_request_mem_region() and devm_ioremap_nocache() calls
by a single call to devm_request_and_ioremap() simplifies the code.

Signed-off-by: Thierry Reding <thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
---
 drivers/i2c/busses/i2c-ocores.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index bffd550..1fad4ae 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -283,18 +283,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
 	if (!i2c)
 		return -ENOMEM;
 
-	if (!devm_request_mem_region(&pdev->dev, res->start,
-				     resource_size(res), pdev->name)) {
-		dev_err(&pdev->dev, "Memory region busy\n");
-		return -EBUSY;
-	}
-
-	i2c->base = devm_ioremap_nocache(&pdev->dev, res->start,
-					 resource_size(res));
-	if (!i2c->base) {
-		dev_err(&pdev->dev, "Unable to map registers\n");
-		return -EIO;
-	}
+	i2c->base = devm_request_and_ioremap(&pdev->dev, res);
+	if (!i2c->base)
+		return -EADDRNOTAVAIL;
 
 	pdata = pdev->dev.platform_data;
 	if (pdata) {
-- 
1.7.11.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: i2c-ocores: Use devm_request_and_ioremap()
       [not found] ` <1344408872-1051-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
@ 2012-10-15  7:10   ` Jean Delvare
       [not found]     ` <20121015091015.2887fcb9-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Jean Delvare @ 2012-10-15  7:10 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Peter Korsgaard, Ben Dooks (embedded platforms),
	Wolfram Sang (embedded platforms),
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Hi Thierry,

On Wed,  8 Aug 2012 08:54:32 +0200, Thierry Reding wrote:
> Replacing the devm_request_mem_region() and devm_ioremap_nocache() calls
> by a single call to devm_request_and_ioremap() simplifies the code.
> 
> Signed-off-by: Thierry Reding <thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
> ---
>  drivers/i2c/busses/i2c-ocores.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
> index bffd550..1fad4ae 100644
> --- a/drivers/i2c/busses/i2c-ocores.c
> +++ b/drivers/i2c/busses/i2c-ocores.c
> @@ -283,18 +283,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
>  	if (!i2c)
>  		return -ENOMEM;
>  
> -	if (!devm_request_mem_region(&pdev->dev, res->start,
> -				     resource_size(res), pdev->name)) {
> -		dev_err(&pdev->dev, "Memory region busy\n");
> -		return -EBUSY;
> -	}
> -
> -	i2c->base = devm_ioremap_nocache(&pdev->dev, res->start,
> -					 resource_size(res));
> -	if (!i2c->base) {
> -		dev_err(&pdev->dev, "Unable to map registers\n");
> -		return -EIO;
> -	}
> +	i2c->base = devm_request_and_ioremap(&pdev->dev, res);
> +	if (!i2c->base)
> +		return -EADDRNOTAVAIL;

I would suggest sticking to -EBUSY, AFAIK EADDRNOTAVAIL is for network
address errors.

>  
>  	pdata = pdev->dev.platform_data;
>  	if (pdata) {

-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: i2c-ocores: Use devm_request_and_ioremap()
       [not found]     ` <20121015091015.2887fcb9-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
@ 2012-10-15  7:21       ` Thierry Reding
       [not found]         ` <20121015072141.GA18741-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Thierry Reding @ 2012-10-15  7:21 UTC (permalink / raw)
  To: Jean Delvare
  Cc: Peter Korsgaard, Ben Dooks (embedded platforms),
	Wolfram Sang (embedded platforms),
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 1750 bytes --]

On Mon, Oct 15, 2012 at 09:10:15AM +0200, Jean Delvare wrote:
> Hi Thierry,
> 
> On Wed,  8 Aug 2012 08:54:32 +0200, Thierry Reding wrote:
> > Replacing the devm_request_mem_region() and devm_ioremap_nocache() calls
> > by a single call to devm_request_and_ioremap() simplifies the code.
> > 
> > Signed-off-by: Thierry Reding <thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
> > ---
> >  drivers/i2c/busses/i2c-ocores.c | 15 +++------------
> >  1 file changed, 3 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
> > index bffd550..1fad4ae 100644
> > --- a/drivers/i2c/busses/i2c-ocores.c
> > +++ b/drivers/i2c/busses/i2c-ocores.c
> > @@ -283,18 +283,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
> >  	if (!i2c)
> >  		return -ENOMEM;
> >  
> > -	if (!devm_request_mem_region(&pdev->dev, res->start,
> > -				     resource_size(res), pdev->name)) {
> > -		dev_err(&pdev->dev, "Memory region busy\n");
> > -		return -EBUSY;
> > -	}
> > -
> > -	i2c->base = devm_ioremap_nocache(&pdev->dev, res->start,
> > -					 resource_size(res));
> > -	if (!i2c->base) {
> > -		dev_err(&pdev->dev, "Unable to map registers\n");
> > -		return -EIO;
> > -	}
> > +	i2c->base = devm_request_and_ioremap(&pdev->dev, res);
> > +	if (!i2c->base)
> > +		return -EADDRNOTAVAIL;
> 
> I would suggest sticking to -EBUSY, AFAIK EADDRNOTAVAIL is for network
> address errors.

Actually the kerneldoc comment for devm_request_and_ioremap()
(lib/devres.c) explicitly lists this as the error code to return on
failure. EBUSY could be misleading since the error could just as well
come from a failed ioremap().

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: i2c-ocores: Use devm_request_and_ioremap()
       [not found]         ` <20121015072141.GA18741-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
@ 2012-10-15  7:34           ` Jean Delvare
  0 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2012-10-15  7:34 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Peter Korsgaard, Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Mon, 15 Oct 2012 09:21:41 +0200, Thierry Reding wrote:
> On Mon, Oct 15, 2012 at 09:10:15AM +0200, Jean Delvare wrote:
> > On Wed,  8 Aug 2012 08:54:32 +0200, Thierry Reding wrote:
> > > Replacing the devm_request_mem_region() and devm_ioremap_nocache() calls
> > > by a single call to devm_request_and_ioremap() simplifies the code.
> > > 
> > > Signed-off-by: Thierry Reding <thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
> > > ---
> > >  drivers/i2c/busses/i2c-ocores.c | 15 +++------------
> > >  1 file changed, 3 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
> > > index bffd550..1fad4ae 100644
> > > --- a/drivers/i2c/busses/i2c-ocores.c
> > > +++ b/drivers/i2c/busses/i2c-ocores.c
> > > @@ -283,18 +283,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
> > >  	if (!i2c)
> > >  		return -ENOMEM;
> > >  
> > > -	if (!devm_request_mem_region(&pdev->dev, res->start,
> > > -				     resource_size(res), pdev->name)) {
> > > -		dev_err(&pdev->dev, "Memory region busy\n");
> > > -		return -EBUSY;
> > > -	}
> > > -
> > > -	i2c->base = devm_ioremap_nocache(&pdev->dev, res->start,
> > > -					 resource_size(res));
> > > -	if (!i2c->base) {
> > > -		dev_err(&pdev->dev, "Unable to map registers\n");
> > > -		return -EIO;
> > > -	}
> > > +	i2c->base = devm_request_and_ioremap(&pdev->dev, res);
> > > +	if (!i2c->base)
> > > +		return -EADDRNOTAVAIL;
> > 
> > I would suggest sticking to -EBUSY, AFAIK EADDRNOTAVAIL is for network
> > address errors.
> 
> Actually the kerneldoc comment for devm_request_and_ioremap()
> (lib/devres.c) explicitly lists this as the error code to return on
> failure. EBUSY could be misleading since the error could just as well
> come from a failed ioremap().

Ah, my bad, I missed that comment.

It's probably not relevant as I'm not in charge of the devm
infrastructure, but I don't like it. There are 3 different possible
causes of failure for devm_request_and_ioremap, and the caller can't
tell which one happened. We have ERR_PTR for cases like this... OTOH I
guess the caller wouldn't behave differently based on the error code,
so it probably doesn't matter that much. So...

Acked-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>

Wolfram, can you please pick this patch?

Thanks,
-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: i2c-ocores: Use devm_request_and_ioremap()
  2012-08-08  6:54 [PATCH] i2c: i2c-ocores: Use devm_request_and_ioremap() Thierry Reding
       [not found] ` <1344408872-1051-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
@ 2012-11-13 11:19 ` Wolfram Sang
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2012-11-13 11:19 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Peter Korsgaard, Jean Delvare (PC drivers, core),
	Ben Dooks (embedded platforms), linux-i2c, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

On Wed, Aug 08, 2012 at 08:54:32AM +0200, Thierry Reding wrote:
> Replacing the devm_request_mem_region() and devm_ioremap_nocache() calls
> by a single call to devm_request_and_ioremap() simplifies the code.
> 
> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>

Applied to for-next, thanks.

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-13 11:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-08  6:54 [PATCH] i2c: i2c-ocores: Use devm_request_and_ioremap() Thierry Reding
     [not found] ` <1344408872-1051-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2012-10-15  7:10   ` Jean Delvare
     [not found]     ` <20121015091015.2887fcb9-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-10-15  7:21       ` Thierry Reding
     [not found]         ` <20121015072141.GA18741-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
2012-10-15  7:34           ` Jean Delvare
2012-11-13 11:19 ` Wolfram Sang

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).