Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] MIPS: unsigned result >= 0 is always true
@ 2008-11-29 14:45 roel kluin
  0 siblings, 0 replies; only message in thread
From: roel kluin @ 2008-11-29 14:45 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips

unsigned result >= 0 is always true. Make sure that the return value
is zero or more if atomic_sub is successful.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
UNTESTED! please confirm whether this is the right fix.

diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
index 1232be3..e0b5604 100644
--- a/arch/mips/include/asm/atomic.h
+++ b/arch/mips/include/asm/atomic.h
@@ -248,7 +248,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
  */
 static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
 {
-	unsigned long result;
+	int result;
 
 	smp_llsc_mb();
 
@@ -296,9 +296,10 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
 
 		raw_local_irq_save(flags);
 		result = v->counter;
-		result -= i;
-		if (result >= 0)
-			v->counter = result;
+		if (v->counter >= i)
+			v->counter -= i;
+		else
+			result -= i;
 		raw_local_irq_restore(flags);
 	}
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-11-29 14:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-29 14:45 [PATCH] MIPS: unsigned result >= 0 is always true roel kluin

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