All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Felipe Balbi <balbi@ti.com>
Cc: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Jon Hunter <jon-hunter@ti.com>, Tony Lindgren <tony@atomide.com>,
	Afzal Mohammed <afzal@ti.com>
Subject: Re: [PATCH 3/7] ARM: omap2: gpmc: Fix gpmc_cs_reserved() return value
Date: Sat, 9 Feb 2013 15:14:33 -0300	[thread overview]
Message-ID: <20130209181432.GD32349@localhost> (raw)
In-Reply-To: <20130209165335.GA13338@arwen.pp.htv.fi>

Hi Felipe,

On Sat, Feb 09, 2013 at 06:53:35PM +0200, Felipe Balbi wrote:
> On Sat, Feb 09, 2013 at 01:38:12PM -0300, Ezequiel Garcia wrote:
> > Fix gpmc_cs_reserved() so it returns 0 if the chip select
> > is available (not reserved) or an error otherwise.
> > This allows to use the return value directly and return a proper error code.
> > 
> > Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> > ---
> >  arch/arm/mach-omap2/gpmc.c |   12 ++++++++----
> >  1 files changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
> > index bd3bc93..604c1eb 100644
> > --- a/arch/arm/mach-omap2/gpmc.c
> > +++ b/arch/arm/mach-omap2/gpmc.c
> > @@ -452,12 +452,16 @@ static int gpmc_cs_set_reserved(int cs, int reserved)
> >  	return 0;
> >  }
> >  
> > +/* Returns 0 if CS is available (not reseverd) or an error otherwise */
> 
> s/reseverd/reserved/
> 

Indeed.

> >  static int gpmc_cs_reserved(int cs)
> >  {
> >  	if (cs > GPMC_CS_NUM)
> >  		return -ENODEV;
> >  
> > -	return gpmc_cs_map & (1 << cs);
> > +	if (gpmc_cs_map & (1 << cs))
> > +		return -EBUSY;
> > +
> > +	return 0;
> 
> you could use a ternary operator here:
> 
> bit = gpmc_cs_map & (1 << cs);
> 
> return bit ? -EBUSY : 0;
> 
> But to be frank, I'm not sure this makes that much sense, I'd expect
> gpmc_cs_reserved() to return 0 or 1 depending on the state (just as it
> was before). The name of the method asks for a boolean return value.
> 

Well, we can change the return value to a boolean.

However, note that the function 'as it was before' was somewhat inconsistent:
gpmc_cs_reserved returned -ENODEV if the given 'cs' was out of range and
a non-negative integer otherwise, 0 if the cs is available and positive
integer otherwise.

So, what I'm doing here is fixing this by returning an appropriate error
condition or 0 if the CS is available.

If we change it to return a boolean, we won't be able to distinguish
between EBUSY and ENODEV.

Let me know what you prefer and I'll fix it on v2.

Thanks for the review,

-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: ezequiel.garcia@free-electrons.com (Ezequiel Garcia)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/7] ARM: omap2: gpmc: Fix gpmc_cs_reserved() return value
Date: Sat, 9 Feb 2013 15:14:33 -0300	[thread overview]
Message-ID: <20130209181432.GD32349@localhost> (raw)
In-Reply-To: <20130209165335.GA13338@arwen.pp.htv.fi>

Hi Felipe,

On Sat, Feb 09, 2013 at 06:53:35PM +0200, Felipe Balbi wrote:
> On Sat, Feb 09, 2013 at 01:38:12PM -0300, Ezequiel Garcia wrote:
> > Fix gpmc_cs_reserved() so it returns 0 if the chip select
> > is available (not reserved) or an error otherwise.
> > This allows to use the return value directly and return a proper error code.
> > 
> > Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> > ---
> >  arch/arm/mach-omap2/gpmc.c |   12 ++++++++----
> >  1 files changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
> > index bd3bc93..604c1eb 100644
> > --- a/arch/arm/mach-omap2/gpmc.c
> > +++ b/arch/arm/mach-omap2/gpmc.c
> > @@ -452,12 +452,16 @@ static int gpmc_cs_set_reserved(int cs, int reserved)
> >  	return 0;
> >  }
> >  
> > +/* Returns 0 if CS is available (not reseverd) or an error otherwise */
> 
> s/reseverd/reserved/
> 

Indeed.

> >  static int gpmc_cs_reserved(int cs)
> >  {
> >  	if (cs > GPMC_CS_NUM)
> >  		return -ENODEV;
> >  
> > -	return gpmc_cs_map & (1 << cs);
> > +	if (gpmc_cs_map & (1 << cs))
> > +		return -EBUSY;
> > +
> > +	return 0;
> 
> you could use a ternary operator here:
> 
> bit = gpmc_cs_map & (1 << cs);
> 
> return bit ? -EBUSY : 0;
> 
> But to be frank, I'm not sure this makes that much sense, I'd expect
> gpmc_cs_reserved() to return 0 or 1 depending on the state (just as it
> was before). The name of the method asks for a boolean return value.
> 

Well, we can change the return value to a boolean.

However, note that the function 'as it was before' was somewhat inconsistent:
gpmc_cs_reserved returned -ENODEV if the given 'cs' was out of range and
a non-negative integer otherwise, 0 if the cs is available and positive
integer otherwise.

So, what I'm doing here is fixing this by returning an appropriate error
condition or 0 if the CS is available.

If we change it to return a boolean, we won't be able to distinguish
between EBUSY and ENODEV.

Let me know what you prefer and I'll fix it on v2.

Thanks for the review,

-- 
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

  reply	other threads:[~2013-02-09 18:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-09 16:38 [PATCH 0/7] ARM: omap2: GPMC cleanup Ezequiel Garcia
2013-02-09 16:38 ` Ezequiel Garcia
2013-02-09 16:38 ` [PATCH 1/7] ARM: omap2: gpmc: Mark local scoped functions static Ezequiel Garcia
2013-02-09 16:38   ` Ezequiel Garcia
2013-02-09 16:38 ` [PATCH 2/7] ARM: omap2: gpmc: Remove unused gpmc_round_ns_to_ticks() function Ezequiel Garcia
2013-02-09 16:38   ` Ezequiel Garcia
2013-02-09 16:38 ` [PATCH 3/7] ARM: omap2: gpmc: Fix gpmc_cs_reserved() return value Ezequiel Garcia
2013-02-09 16:38   ` Ezequiel Garcia
2013-02-09 16:53   ` Felipe Balbi
2013-02-09 16:53     ` Felipe Balbi
2013-02-09 18:14     ` Ezequiel Garcia [this message]
2013-02-09 18:14       ` Ezequiel Garcia
2013-02-09 20:56       ` Felipe Balbi
2013-02-09 20:56         ` Felipe Balbi
2013-02-09 16:38 ` [PATCH 4/7] ARM: omap2: gpmc-nand: Print something useful on CS request failure Ezequiel Garcia
2013-02-09 16:38   ` Ezequiel Garcia
2013-02-09 16:38 ` [PATCH 5/7] ARM: omap2: gpmc-onenand: " Ezequiel Garcia
2013-02-09 16:38   ` Ezequiel Garcia
2013-02-09 16:38 ` [PATCH 6/7] ARM: omap2: gpmc-onenand: Replace pr_err() with dev_err() Ezequiel Garcia
2013-02-09 16:38   ` Ezequiel Garcia
2013-02-09 16:38 ` [PATCH 7/7] ARM: omap2: gpmc-onenand: Replace printk KERN_ERR with dev_warn() Ezequiel Garcia
2013-02-09 16:38   ` Ezequiel Garcia
2013-02-09 16:55   ` Felipe Balbi
2013-02-09 16:55     ` Felipe Balbi
2013-02-09 18:05     ` Ezequiel Garcia
2013-02-09 18:05       ` Ezequiel Garcia
2013-02-09 20:58       ` Felipe Balbi
2013-02-09 20:58         ` Felipe Balbi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130209181432.GD32349@localhost \
    --to=ezequiel.garcia@free-electrons.com \
    --cc=afzal@ti.com \
    --cc=balbi@ti.com \
    --cc=jon-hunter@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.