Skip to content

Commit c84598b

Browse files
Shaohua Litorvalds
authored andcommitted
percpu_counter: change return value and add comments
The percpu_counter_*_positive() API in UP case doesn't check if return value is positive. Add comments to explain why we don't. Also if count < 0, returns 0 instead of 1 for *read_positive(). [akpm@linux-foundation.org: tweak comment] Signed-off-by: Shaohua Li <shaohua.li@intel.com> Acked-by: Eric Dumazet <eric.dumazet@gmail.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3c8f370 commit c84598b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/linux/percpu_counter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
7575
barrier(); /* Prevent reloads of fbc->count */
7676
if (ret >= 0)
7777
return ret;
78-
return 1;
78+
return 0;
7979
}
8080

8181
static inline int percpu_counter_initialized(struct percpu_counter *fbc)
@@ -133,6 +133,10 @@ static inline s64 percpu_counter_read(struct percpu_counter *fbc)
133133
return fbc->count;
134134
}
135135

136+
/*
137+
* percpu_counter is intended to track positive numbers. In the UP case the
138+
* number should never be negative.
139+
*/
136140
static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
137141
{
138142
return fbc->count;

0 commit comments

Comments
 (0)