Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
  2008-11-03 14:29 [PATCH] provide functions for gpio configuration Phil Sutter
@ 2008-11-03 14:30 ` Phil Sutter
  2008-11-03 14:48   ` Atsushi Nemoto
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2008-11-03 14:30 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Sergei Shtylyov, linux-mips

The algorithm works unconditionally. If bitval is one, the first line is
a no op and the second line sets the bit at offset position. Vice versa,
if bitval is zero, the first line clears the bit at offset position and
the second line is a no op.

Signed-off-by: Phil Sutter <n0-1@freewrt.org>
---
 arch/mips/rb532/gpio.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/rb532/gpio.c b/arch/mips/rb532/gpio.c
index 0e84c8a..ba9a0c4 100644
--- a/arch/mips/rb532/gpio.c
+++ b/arch/mips/rb532/gpio.c
@@ -124,8 +124,8 @@ static inline void rb532_set_bit(unsigned bitval,
 	local_irq_save(flags);
 
 	val = readl(ioaddr);
-	val &= ~( ~bitval << offset );   /* unset bit if bitval == 0 */
-	val |=  (  bitval << offset );   /* set bit if bitval == 1 */
+	val &= ~(!bitval << offset);   /* unset bit if bitval == 0 */
+	val |=  (bitval << offset);   /* set bit if bitval == 1 */
 	writel(val, ioaddr);
 
 	local_irq_restore(flags);
-- 
1.5.6.4

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

* Re: [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
  2008-11-03 14:30 ` [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit() Phil Sutter
@ 2008-11-03 14:48   ` Atsushi Nemoto
  2008-11-03 15:05     ` Phil Sutter
  0 siblings, 1 reply; 7+ messages in thread
From: Atsushi Nemoto @ 2008-11-03 14:48 UTC (permalink / raw)
  To: n0-1; +Cc: ralf, sshtylyov, linux-mips

On Mon,  3 Nov 2008 15:30:25 +0100, Phil Sutter <n0-1@freewrt.org> wrote:
> The algorithm works unconditionally. If bitval is one, the first line is
> a no op and the second line sets the bit at offset position. Vice versa,
> if bitval is zero, the first line clears the bit at offset position and
> the second line is a no op.

Well, the linux gpio framework uses 0 for low, _nonzero_ for high.
You should not assume the bitval is 0 or 1.

	val &= ~(!bitval << offset);   /* unset bit if bitval == 0 */
	val |= (!!bitval << offset);   /* set bit if bitval != 0 */

would be safe here.  Or you should ensure the bitval is 0 or 1
somewhere.

---
Atsushi Nemoto

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

* Re: [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
  2008-11-03 14:48   ` Atsushi Nemoto
@ 2008-11-03 15:05     ` Phil Sutter
  2008-11-11 23:09       ` Phil Sutter
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2008-11-03 15:05 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: ralf, sshtylyov, linux-mips

Hi,

On Mon, Nov 03, 2008 at 11:48:56PM +0900, Atsushi Nemoto wrote:
> Well, the linux gpio framework uses 0 for low, _nonzero_ for high.
> You should not assume the bitval is 0 or 1.

Good point. I was thinking about this potential problem, too. This is
why the mentioned function contains the following line (sadly too far
off to occur in the patch):

| bitval = !!bitval;              /* map parameter to {0,1} */

I put that separately to not make the below lines even more unreadable.

> 	val &= ~(!bitval << offset);   /* unset bit if bitval == 0 */
> 	val |= (!!bitval << offset);   /* set bit if bitval != 0 */

But as a boolean inverse has to be used anyway, your solution looks more
elegant than mine.

Greetings, Phil

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

* [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
  2008-11-03 15:05     ` Phil Sutter
@ 2008-11-11 23:09       ` Phil Sutter
  2009-01-29 16:27         ` Ralf Baechle
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2008-11-11 23:09 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips

This is a simplified version of the original fix, thanks to Atsushi Nemoto for
the hint.

Greetings, Phil

---

The algorithm works unconditionally. If bitval is one, the first line is
a no op and the second line sets the bit at offset position. Vice versa,
if bitval is zero, the first line clears the bit at offset position and
the second line is a no op.

Signed-off-by: Phil Sutter <n0-1@freewrt.org>
---
 arch/mips/rb532/gpio.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/mips/rb532/gpio.c b/arch/mips/rb532/gpio.c
index 0e84c8a..e35cb75 100644
--- a/arch/mips/rb532/gpio.c
+++ b/arch/mips/rb532/gpio.c
@@ -119,13 +119,11 @@ static inline void rb532_set_bit(unsigned bitval,
 	unsigned long flags;
 	u32 val;
 
-	bitval = !!bitval;              /* map parameter to {0,1} */
-
 	local_irq_save(flags);
 
 	val = readl(ioaddr);
-	val &= ~( ~bitval << offset );   /* unset bit if bitval == 0 */
-	val |=  (  bitval << offset );   /* set bit if bitval == 1 */
+	val &= ~(!bitval << offset);   /* unset bit if bitval == 0 */
+	val |= (!!bitval << offset);   /* set bit if bitval == 1 */
 	writel(val, ioaddr);
 
 	local_irq_restore(flags);
-- 
1.5.6.4

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

* [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
@ 2008-11-11 23:14 Phil Sutter
  2008-11-11 23:26 ` Phil Sutter
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2008-11-11 23:14 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, florian

This is a simplified version of the original fix, thanks to Atsushi Nemoto for
the hint.

Greetings, Phil

---

The algorithm works unconditionally. If bitval is one, the first line is
a no op and the second line sets the bit at offset position. Vice versa,
if bitval is zero, the first line clears the bit at offset position and
the second line is a no op.

Signed-off-by: Phil Sutter <n0-1@freewrt.org>
---
 arch/mips/rb532/gpio.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/mips/rb532/gpio.c b/arch/mips/rb532/gpio.c
index 0e84c8a..e35cb75 100644
--- a/arch/mips/rb532/gpio.c
+++ b/arch/mips/rb532/gpio.c
@@ -119,13 +119,11 @@ static inline void rb532_set_bit(unsigned bitval,
 	unsigned long flags;
 	u32 val;
 
-	bitval = !!bitval;              /* map parameter to {0,1} */
-
 	local_irq_save(flags);
 
 	val = readl(ioaddr);
-	val &= ~( ~bitval << offset );   /* unset bit if bitval == 0 */
-	val |=  (  bitval << offset );   /* set bit if bitval == 1 */
+	val &= ~(!bitval << offset);   /* unset bit if bitval == 0 */
+	val |= (!!bitval << offset);   /* set bit if bitval == 1 */
 	writel(val, ioaddr);
 
 	local_irq_restore(flags);
-- 
1.5.6.4

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

* Re: [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
  2008-11-11 23:14 [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit() Phil Sutter
@ 2008-11-11 23:26 ` Phil Sutter
  0 siblings, 0 replies; 7+ messages in thread
From: Phil Sutter @ 2008-11-11 23:26 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, florian

On Wed, Nov 12, 2008 at 12:14:40AM +0100, Phil Sutter wrote:
> This is a simplified version of the original fix, thanks to Atsushi Nemoto for
> the hint.

Shame on me, I got the wrong patch and so this is just a copy of the
mail sent before, but with a missing In-Reply-To header.

Sorry for that, Phil

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

* Re: [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
  2008-11-11 23:09       ` Phil Sutter
@ 2009-01-29 16:27         ` Ralf Baechle
  0 siblings, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2009-01-29 16:27 UTC (permalink / raw)
  To: Phil Sutter; +Cc: linux-mips

On Wed, Nov 12, 2008 at 12:09:30AM +0100, Phil Sutter wrote:

thanks, applied.

  Ralf

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

end of thread, other threads:[~2009-01-29 16:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-11 23:14 [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit() Phil Sutter
2008-11-11 23:26 ` Phil Sutter
  -- strict thread matches above, loose matches on Subject: below --
2008-11-03 14:29 [PATCH] provide functions for gpio configuration Phil Sutter
2008-11-03 14:30 ` [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit() Phil Sutter
2008-11-03 14:48   ` Atsushi Nemoto
2008-11-03 15:05     ` Phil Sutter
2008-11-11 23:09       ` Phil Sutter
2009-01-29 16:27         ` Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox