Skip to content

Commit 3f888d1

Browse files
mpegregkh
authored andcommitted
powerpc/64: Fix atomic64_inc_not_zero() to return an int
commit 01e6a61 upstream. Although it's not documented anywhere, there is an expectation that atomic64_inc_not_zero() returns a result which fits in an int. This is the behaviour implemented on all arches except powerpc. This has caused at least one bug in practice, in the percpu-refcount code, where the long result from our atomic64_inc_not_zero() was truncated to an int leading to lost references and stuck systems. That was worked around in that code in commit 966d2b0 ("percpu-refcount: fix reference leak during percpu-atomic transition"). To the best of my grepping abilities there are no other callers in-tree which truncate the value, but we should fix it anyway. Because the breakage is subtle and potentially very harmful I'm also tagging it for stable. Code generation is largely unaffected because in most cases the callers are just using the result for a test anyway. In particular the case of fget() that was mentioned in commit a6cf7ed ("powerpc/atomic: Implement atomic*_inc_not_zero") generates exactly the same code. Fixes: a6cf7ed ("powerpc/atomic: Implement atomic*_inc_not_zero") Noticed-by: Linus Torvalds <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c50e87e commit 3f888d1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/powerpc/include/asm/atomic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
460460
* Atomically increments @v by 1, so long as @v is non-zero.
461461
* Returns non-zero if @v was non-zero, and zero otherwise.
462462
*/
463-
static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
463+
static __inline__ int atomic64_inc_not_zero(atomic64_t *v)
464464
{
465465
long t1, t2;
466466

@@ -479,7 +479,7 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
479479
: "r" (&v->counter)
480480
: "cc", "xer", "memory");
481481

482-
return t1;
482+
return t1 != 0;
483483
}
484484

485485
#endif /* __powerpc64__ */

0 commit comments

Comments
 (0)