[PATCH] MIPS: unsigned result >= 0 is always true

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
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);
 	}
 



[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux