linux-mips
[Top] [All Lists]

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

To: ralf@linux-mips.org
Subject: [PATCH] MIPS: unsigned result >= 0 is always true
From: roel kluin <roel.kluin@gmail.com>
Date: Sat, 29 Nov 2008 09:45:08 -0500
Cc: linux-mips@linux-mips.org
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:content-type :content-transfer-encoding; bh=NlMTtXDyEZlkaEaQb+s9hnZux9rYQ33ngRsG+90sdzg=; b=dIYAEyJBP/Sc5p3Iz3bkOB5CSgNRq2MQMwx9EskHn3MXdPOjbyV3ogEsS1Uujhpwin Lbv2SdHTse1tFEBLHAx/X54KymEqv1PYZ27xW0FF3SGTrrzYThpMa74HxatNRSVK7dJS GcJ5Ci5jUMgBXsEW8S5Ok5trs6QzEUTtr0QBI=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; b=T4zKDBUqBQxtjbaDsuQfmQmYfxlXOMgIDAYLjwdtGi3ZRYb+4ap6cXgIiBVIagc5LI lBNtT5iAz5tPl/3Ms4j3N1S8Xb96ORRcsTrT1TgW8Y868cTAW6uITDiqWLP/ydRsH0AQ KMS2IORDr+NaMFQpSKHQhcLhDzFaZVhIwVCu8=
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080110)
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);
        }
 


<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH] MIPS: unsigned result >= 0 is always true, roel kluin <=