From: Roel Kluin <roel.kluin@gmail.com>
To: ralf@linux-mips.org
Cc: linux-mips@linux-mips.org
Subject: [PATCH] MIPS: unsigned result is always greater than 0
Date: Fri, 02 Jan 2009 16:09:59 +0100 [thread overview]
Message-ID: <495E2E47.6080605@gmail.com> (raw)
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);
}
next reply other threads:[~2009-01-02 15:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-02 15:09 Roel Kluin [this message]
2009-01-06 21:46 ` [PATCH] MIPS: unsigned result is always greater than 0 David VomLehn (dvomlehn)
2009-01-06 21:46 ` David VomLehn (dvomlehn)
2009-01-12 1:26 ` Ralf Baechle
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=495E2E47.6080605@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