linux-mips
[Top] [All Lists]

[PATCH] MIPS: unsigned result is always greater than 0

To: ralf@linux-mips.org
Subject: [PATCH] MIPS: unsigned result is always greater than 0
From: Roel Kluin <roel.kluin@gmail.com>
Date: Fri, 02 Jan 2009 16:09:59 +0100
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=dmnEB+GhJDgh6sg5w0OitCDzYTiMlF4/FRw0HkgpiYY=; b=KMESLaVQtX8Qg2RU6kZSYcnWFxIW2ysJEHk2IdKpaiFM2Y/odzb5xu3xJdIMytY9+c kiVtbHoGLdEq/6deap9pZyub2JhnpMlmqjmoYAEJPP5ENUSzbkfVbqlEg1j30kIdREpi uEnjJn83OX563KjdQ2QBEFNfYT7gCRYAtsHjo=
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=uGvGsUj8IlYgw6v6uhX4Rxwm2CYZK/GwUqDCCjj690n5q9T5zZeA5VwBcqY7uCgZOf 6SZ2hrasBlmvNfz3Ab+06mry2DuqBnHFvDmPengzaxPXIja52UEcWWqENwXGZu5e8rN0 YKFE1Td7A8MnjRQWtkN902Rd+8IMCrLFB5PEs=
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org
User-agent: Thunderbird 2.0.0.18 (X11/20081105)
unsigned result is always greater than 0

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
I cannot determine whether the same bug occurs as well in assembly.
Also shouldn't similar checks occur in atomic64_sub_return and in
atomic64_add_return for negative values of i?

diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
index 1232be3..3cd07a9 100644
--- a/arch/mips/include/asm/atomic.h
+++ b/arch/mips/include/asm/atomic.h
@@ -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)
+               if (i <= result) {
+                       result -= i;
                        v->counter = result;
+               }
                raw_local_irq_restore(flags);
        }
 
@@ -677,9 +678,10 @@ static __inline__ long atomic64_sub_if_positive(long i, 
atomic64_t * v)
 
                raw_local_irq_save(flags);
                result = v->counter;
-               result -= i;
-               if (result >= 0)
+               if (i >= result) {
+                       result -= i;
                        v->counter = result;
+               }
                raw_local_irq_restore(flags);
        }
 

<Prev in Thread] Current Thread [Next in Thread>