Skip to contentSkip to conversation

MIPS: unsigned result >= 0 is always true

PATCH New roel kluin 1 participant 1 message Nov 29, 2008

Subsystems (2)
lore
Share & tools
lore

roel kluin

author
#0 lore raw

PATCH 1/1 MIPS: unsigned result >= 0 is always true

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

---
UNTESTED! please confirm whether this is the right fix.

arch/mips/include/asm/atomic.h +5 -4
index 1232be3..e0b5604 100644
@@ -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);
 	}