Skip to contentSkip to conversation

Fix atomic64 return value conventions (v2)

PATCH In review Luca Barbieri 1 participant 11 messages Mar 1, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix atomic64 return value conventions (v2)

Changes in v2:
- Resent patches with more verbose descriptions

This patchset fixes the return value conventions in the atomic64 test, generic implementation and the x86-32 implementation in x86/tip/atomic.

Luca Barbieri (5):
lib: fix atomic64_add_unless test
x86-32: fix atomic64_add_unless return value convention
lib: fix atomic64_add_unless return value convention
lib: fix atomic64_inc_not_zero test
x86-32: fix atomic64_inc_not_zero return value convention

 arch/x86/lib/atomic64_386_32.S |    7 +++----
 arch/x86/lib/atomic64_cx8_32.S |    7 +++----
 lib/atomic64.c                 |    4 ++--
 lib/atomic64_test.c            |   10 +++++-----
 4 files changed, 13 insertions(+), 15 deletions(-)
#1 lore raw

PATCH 1/5 lib: fix atomic64_add_unless test

atomic64_add_unless must return 1 if it perfomed the add and 0 otherwise. The test assumed the opposite convention.

---
 lib/atomic64_test.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/atomic64_test.c +2 -2
index 58efdab..ee8e6de 100644
@@ -104,11 +104,11 @@ static __init int test_atomic64(void)
 	BUG_ON(v.counter != r);
 
 	INIT(v0);
-	BUG_ON(!atomic64_add_unless(&v, one, v0));
+	BUG_ON(atomic64_add_unless(&v, one, v0));
 	BUG_ON(v.counter != r);
 
 	INIT(v0);
-	BUG_ON(atomic64_add_unless(&v, one, v1));
+	BUG_ON(!atomic64_add_unless(&v, one, v1));
 	r += one;
 	BUG_ON(v.counter != r);
 
Signature · 1 line
1.6.6.1.476.g01ddb
#2 lore raw

[tip:x86/atomic] lib: Fix atomic64_add_unless test

Commit-ID:  9efbcd590243045111670c171a951923b877b57d
Gitweb:     http://git.kernel.org/tip/9efbcd590243045111670c171a951923b877b57d
Author:     Luca Barbieri <[email protected]>
AuthorDate: Mon, 1 Mar 2010 19:55:45 +0100
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 1 Mar 2010 11:38:46 -0800

lib: Fix atomic64_add_unless test

atomic64_add_unless must return 1 if it perfomed the add and 0 otherwise. The test assumed the opposite convention.

LKML-Reference: <[email protected]>

---
 lib/atomic64_test.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/atomic64_test.c +2 -2
index 58efdab..ee8e6de 100644
@@ -104,11 +104,11 @@ static __init int test_atomic64(void)
 	BUG_ON(v.counter != r);
 
 	INIT(v0);
-	BUG_ON(!atomic64_add_unless(&v, one, v0));
+	BUG_ON(atomic64_add_unless(&v, one, v0));
 	BUG_ON(v.counter != r);
 
 	INIT(v0);
-	BUG_ON(atomic64_add_unless(&v, one, v1));
+	BUG_ON(!atomic64_add_unless(&v, one, v1));
 	r += one;
 	BUG_ON(v.counter != r);
 
#3 lore raw

PATCH 2/5 x86-32: fix atomic64_add_unless return value convention

In reply to Luca Barbieri

atomic64_add_unless must return 1 if it perfomed the add and 0 otherwise. The implementation did the opposite thing.

---
 arch/x86/lib/atomic64_386_32.S |    4 ++--
 arch/x86/lib/atomic64_cx8_32.S |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/lib/atomic64_386_32.S +2 -2
index 5db07fe..a2f847c 100644
@@ -133,13 +133,13 @@ BEGIN add_unless %ecx
 1:
 	movl %eax,  ($v)
 	movl %edx, 4($v)
-	xorl %eax, %eax
+	movl $1, %eax
 2:
 RETURN
 3:
 	cmpl %edx, %edi
 	jne 1b
-	movl $1, %eax
+	xorl %eax, %eax
 	jmp 2b
 END_
 
arch/x86/lib/atomic64_cx8_32.S +2 -2
index e49c4eb..d0e37b1 100644
@@ -180,7 +180,7 @@ ENTRY(atomic64_add_unless_cx8)
 	cmpxchg8b (%ebp)
 	jne 1b
 
-	xorl %eax, %eax
+	movl $1, %eax
 3:
 	addl $8, %esp
 	CFI_ADJUST_CFA_OFFSET -8
@@ -190,7 +190,7 @@ ENTRY(atomic64_add_unless_cx8)
 4:
 	cmpl %edx, 4(%esp)
 	jne 2b
-	movl $1, %eax
+	xorl %eax, %eax
 	jmp 3b
 	CFI_ENDPROC
 ENDPROC(atomic64_add_unless_cx8)
Signature · 1 line
1.6.6.1.476.g01ddb
#4 lore raw

[tip:x86/atomic] x86-32: Fix atomic64_add_unless return value convention

Commit-ID:  6e6104fe085026e6ef82cc5cc303d6c8ceb7e411
Gitweb:     http://git.kernel.org/tip/6e6104fe085026e6ef82cc5cc303d6c8ceb7e411
Author:     Luca Barbieri <[email protected]>
AuthorDate: Mon, 1 Mar 2010 19:55:46 +0100
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 1 Mar 2010 11:38:46 -0800

x86-32: Fix atomic64_add_unless return value convention

atomic64_add_unless must return 1 if it perfomed the add and 0 otherwise. The implementation did the opposite thing.

LKML-Reference: <[email protected]>

---
 arch/x86/lib/atomic64_386_32.S |    4 ++--
 arch/x86/lib/atomic64_cx8_32.S |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/lib/atomic64_386_32.S +2 -2
index 5db07fe..a2f847c 100644
@@ -133,13 +133,13 @@ BEGIN add_unless %ecx
 1:
 	movl %eax,  ($v)
 	movl %edx, 4($v)
-	xorl %eax, %eax
+	movl $1, %eax
 2:
 RETURN
 3:
 	cmpl %edx, %edi
 	jne 1b
-	movl $1, %eax
+	xorl %eax, %eax
 	jmp 2b
 END_
 
arch/x86/lib/atomic64_cx8_32.S +2 -2
index e49c4eb..d0e37b1 100644
@@ -180,7 +180,7 @@ ENTRY(atomic64_add_unless_cx8)
 	cmpxchg8b (%ebp)
 	jne 1b
 
-	xorl %eax, %eax
+	movl $1, %eax
 3:
 	addl $8, %esp
 	CFI_ADJUST_CFA_OFFSET -8
@@ -190,7 +190,7 @@ ENTRY(atomic64_add_unless_cx8)
 4:
 	cmpl %edx, 4(%esp)
 	jne 2b
-	movl $1, %eax
+	xorl %eax, %eax
 	jmp 3b
 	CFI_ENDPROC
 ENDPROC(atomic64_add_unless_cx8)
#5 lore raw

PATCH 3/5 lib: fix atomic64_add_unless return value convention

In reply to Luca Barbieri

atomic64_add_unless must return 1 if it perfomed the add and 0 otherwise. The generic implementation did the opposite thing.

---
 lib/atomic64.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/atomic64.c +2 -2
index 8bee16e..a21c12b 100644
@@ -162,12 +162,12 @@ int atomic64_add_unless(atomic64_t *v, long long a, long long u)
 {
 	unsigned long flags;
 	spinlock_t *lock = lock_addr(v);
-	int ret = 1;
+	int ret = 0;
 
 	spin_lock_irqsave(lock, flags);
 	if (v->counter != u) {
 		v->counter += a;
-		ret = 0;
+		ret = 1;
 	}
 	spin_unlock_irqrestore(lock, flags);
 	return ret;
Signature · 1 line
1.6.6.1.476.g01ddb
#6 lore raw

[tip:x86/atomic] lib: Fix atomic64_add_unless return value convention

Commit-ID:  97577896f6b9c056fa0a5e9f6a608110cb3dcd33
Gitweb:     http://git.kernel.org/tip/97577896f6b9c056fa0a5e9f6a608110cb3dcd33
Author:     Luca Barbieri <[email protected]>
AuthorDate: Mon, 1 Mar 2010 19:55:47 +0100
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 1 Mar 2010 11:38:46 -0800

lib: Fix atomic64_add_unless return value convention

atomic64_add_unless must return 1 if it perfomed the add and 0 otherwise. The generic implementation did the opposite thing.

LKML-Reference: <[email protected]>

---
 lib/atomic64.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/atomic64.c +2 -2
index 8bee16e..a21c12b 100644
@@ -162,12 +162,12 @@ int atomic64_add_unless(atomic64_t *v, long long a, long long u)
 {
 	unsigned long flags;
 	spinlock_t *lock = lock_addr(v);
-	int ret = 1;
+	int ret = 0;
 
 	spin_lock_irqsave(lock, flags);
 	if (v->counter != u) {
 		v->counter += a;
-		ret = 0;
+		ret = 1;
 	}
 	spin_unlock_irqrestore(lock, flags);
 	return ret;
#7 lore raw

PATCH 4/5 lib: fix atomic64_inc_not_zero test

In reply to Luca Barbieri

atomic64_inc_not_zero must return 1 if it perfomed the add and 0 otherwise. The test assumed the opposite convention.

---
 lib/atomic64_test.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
lib/atomic64_test.c +3 -3
index ee8e6de..f7bb706 100644
@@ -130,16 +130,16 @@ static __init int test_atomic64(void)
 #endif
 
 	INIT(onestwos);
-	BUG_ON(atomic64_inc_not_zero(&v));
+	BUG_ON(!atomic64_inc_not_zero(&v));
 	r += one;
 	BUG_ON(v.counter != r);
 
 	INIT(0);
-	BUG_ON(!atomic64_inc_not_zero(&v));
+	BUG_ON(atomic64_inc_not_zero(&v));
 	BUG_ON(v.counter != r);
 
 	INIT(-one);
-	BUG_ON(atomic64_inc_not_zero(&v));
+	BUG_ON(!atomic64_inc_not_zero(&v));
 	r += one;
 	BUG_ON(v.counter != r);
 
Signature · 1 line
1.6.6.1.476.g01ddb
#8 lore raw

[tip:x86/atomic] lib: Fix atomic64_inc_not_zero test

Commit-ID:  25a304f277ad70166eeae25a4958d2049005c33a
Gitweb:     http://git.kernel.org/tip/25a304f277ad70166eeae25a4958d2049005c33a
Author:     Luca Barbieri <[email protected]>
AuthorDate: Mon, 1 Mar 2010 19:55:48 +0100
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 1 Mar 2010 11:39:02 -0800

lib: Fix atomic64_inc_not_zero test

atomic64_inc_not_zero must return 1 if it perfomed the add and 0 otherwise. The test assumed the opposite convention.

LKML-Reference: <[email protected]>

---
 lib/atomic64_test.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
lib/atomic64_test.c +3 -3
index ee8e6de..f7bb706 100644
@@ -130,16 +130,16 @@ static __init int test_atomic64(void)
 #endif
 
 	INIT(onestwos);
-	BUG_ON(atomic64_inc_not_zero(&v));
+	BUG_ON(!atomic64_inc_not_zero(&v));
 	r += one;
 	BUG_ON(v.counter != r);
 
 	INIT(0);
-	BUG_ON(!atomic64_inc_not_zero(&v));
+	BUG_ON(atomic64_inc_not_zero(&v));
 	BUG_ON(v.counter != r);
 
 	INIT(-one);
-	BUG_ON(atomic64_inc_not_zero(&v));
+	BUG_ON(!atomic64_inc_not_zero(&v));
 	r += one;
 	BUG_ON(v.counter != r);
 
#9 lore raw

PATCH 5/5 x86-32: fix atomic64_inc_not_zero return value convention

In reply to Luca Barbieri

atomic64_inc_not_zero must return 1 if it perfomed the add and 0 otherwise. It was doing the opposite thing.

---
 arch/x86/lib/atomic64_386_32.S |    3 +--
 arch/x86/lib/atomic64_cx8_32.S |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/lib/atomic64_386_32.S +1 -2
index a2f847c..4a5979a 100644
@@ -153,13 +153,12 @@ BEGIN inc_not_zero %esi
 	adcl $0, %edx
 	movl %eax,  ($v)
 	movl %edx, 4($v)
-	xorl %eax, %eax
+	movl $1, %eax
 2:
 RETURN
 3:
 	testl %edx, %edx
 	jne 1b
-	movl $1, %eax
 	jmp 2b
 END_
 
arch/x86/lib/atomic64_cx8_32.S +1 -2
index d0e37b1..71e080d 100644
@@ -212,14 +212,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
 	cmpxchg8b (%esi)
 	jne 1b
 
-	xorl %eax, %eax
+	movl $1, %eax
 3:
 	RESTORE ebx
 	ret
 4:
 	testl %edx, %edx
 	jne 2b
-	movl $1, %eax
 	jmp 3b
 	CFI_ENDPROC
 ENDPROC(atomic64_inc_not_zero_cx8)
Signature · 1 line
1.6.6.1.476.g01ddb
#10 lore raw

[tip:x86/atomic] x86-32: Fix atomic64_inc_not_zero return value convention

Commit-ID:  f3e83131469e29032a700217aa394996107b8fc5
Gitweb:     http://git.kernel.org/tip/f3e83131469e29032a700217aa394996107b8fc5
Author:     Luca Barbieri <[email protected]>
AuthorDate: Mon, 1 Mar 2010 19:55:49 +0100
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 1 Mar 2010 11:39:03 -0800

x86-32: Fix atomic64_inc_not_zero return value convention

atomic64_inc_not_zero must return 1 if it perfomed the add and 0 otherwise. It was doing the opposite thing.

LKML-Reference: <[email protected]>

---
 arch/x86/lib/atomic64_386_32.S |    3 +--
 arch/x86/lib/atomic64_cx8_32.S |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/lib/atomic64_386_32.S +1 -2
index a2f847c..4a5979a 100644
@@ -153,13 +153,12 @@ BEGIN inc_not_zero %esi
 	adcl $0, %edx
 	movl %eax,  ($v)
 	movl %edx, 4($v)
-	xorl %eax, %eax
+	movl $1, %eax
 2:
 RETURN
 3:
 	testl %edx, %edx
 	jne 1b
-	movl $1, %eax
 	jmp 2b
 END_
 
arch/x86/lib/atomic64_cx8_32.S +1 -2
index d0e37b1..71e080d 100644
@@ -212,14 +212,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
 	cmpxchg8b (%esi)
 	jne 1b
 
-	xorl %eax, %eax
+	movl $1, %eax
 3:
 	RESTORE ebx
 	ret
 4:
 	testl %edx, %edx
 	jne 2b
-	movl $1, %eax
 	jmp 3b
 	CFI_ENDPROC
 ENDPROC(atomic64_inc_not_zero_cx8)