diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2007-10-17 02:25:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-17 11:42:44 -0400 |
commit | 3cb4f9fa0c5f3ded9f70f85b70ee6d429834f911 (patch) | |
tree | d1f45445fa98bd41a2f8986781f7c62b470a6b8d /include/linux/percpu_counter.h | |
parent | aa0dff2d09bfa50b7d02714a45920c64568e699d (diff) |
lib: percpu_counter_sub
Hugh spotted that some code does:
percpu_counter_add(&counter, -unsignedlong)
which, when the amount argument is of type s32, sort-of works thanks to
two's-complement. However when we'd change the type to s64 this breaks on 32bit
machines, because the promotion rules zero extend the unsigned number.
Provide percpu_counter_sub() to hide the s64 cast. That is:
percpu_counter_sub(&counter, foo)
is equal to:
percpu_counter_add(&counter, -(s64)foo);
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/percpu_counter.h')
-rw-r--r-- | include/linux/percpu_counter.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h index b84fc8667de8..438a170187ec 100644 --- a/include/linux/percpu_counter.h +++ b/include/linux/percpu_counter.h | |||
@@ -105,4 +105,9 @@ static inline void percpu_counter_dec(struct percpu_counter *fbc) | |||
105 | percpu_counter_add(fbc, -1); | 105 | percpu_counter_add(fbc, -1); |
106 | } | 106 | } |
107 | 107 | ||
108 | static inline void percpu_counter_sub(struct percpu_counter *fbc, s64 amount) | ||
109 | { | ||
110 | percpu_counter_add(fbc, -amount); | ||
111 | } | ||
112 | |||
108 | #endif /* _LINUX_PERCPU_COUNTER_H */ | 113 | #endif /* _LINUX_PERCPU_COUNTER_H */ |