Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: roel kluin <roel.kluin@gmail.com>
To: ralf@linux-mips.org
Cc: linux-mips@linux-mips.org
Subject: [PATCH] MIPS: unsigned result >= 0 is always true
Date: Sat, 29 Nov 2008 09:45:08 -0500	[thread overview]
Message-ID: <49315574.7080006@gmail.com> (raw)

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

                 reply	other threads:[~2008-11-29 14:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49315574.7080006@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox