Skip to contentSkip to conversation

Fix __wait_on_atomic_t() to call the action func if the counter != 0

PATCH In review David Howells 2 participants 4 messages Jul 23, 2013

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

PATCH 1/1 Fix __wait_on_atomic_t() to call the action func if the counter != 0

Fix __wait_on_atomic_t() so that it calls the action func if the counter != 0 rather than if the counter is 0 so as to be analogous to __wait_on_bit().

Thanks to Yacine who found this by visual inspection.

This will affect FS-Cache in that it will could fail to sleep correctly when trying to clean up after a netfs cookie is withdrawn.

cc Yacine Belkadi <[email protected]>
cc Milosz Tanski <[email protected]>
cc Jeff Layton <[email protected]>

---

 kernel/wait.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/wait.c +2 -1
index ce0daa3..dec68bd 100644
@@ -333,7 +333,8 @@ int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q,
 		prepare_to_wait(wq, &q->wait, mode);
 		val = q->key.flags;
 		if (atomic_read(val) == 0)
-			ret = (*action)(val);
+			break;
+		ret = (*action)(val);
 	} while (!ret && atomic_read(val) != 0);
 	finish_wait(wq, &q->wait);
 	return ret;
#1 lore raw
Quoted 23 lines · On Tue, 23 Jul 2013 16:49:24 +0100 David Howells <[email protected]> wrote:

Fix __wait_on_atomic_t() so that it calls the action func if the counter != 0 rather than if the counter is 0 so as to be analogous to __wait_on_bit().

Thanks to Yacine who found this by visual inspection.

This will affect FS-Cache in that it will could fail to sleep correctly when trying to clean up after a netfs cookie is withdrawn.

cc Yacine Belkadi <[email protected]>
cc Milosz Tanski <[email protected]>
cc Jeff Layton <[email protected]>

---

 kernel/wait.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/wait.c +0 -0
index ce0daa3..dec68bd 100644

kernel/wait.c int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q, · line 338

Quoted 7 lines
kernel/wait.c +2 -1
@@ -333,7 +333,8 @@ int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q,
 		prepare_to_wait(wq, &q->wait, mode);
 		val = q->key.flags;
 		if (atomic_read(val) == 0)
-			ret = (*action)(val);
+			break;
+		ret = (*action)(val);
 	} while (!ret && atomic_read(val) != 0);

nit: can you now eliminate the check for "val" in the while condition? It doesn't look like it harms anything, but eliminating it would probably simplify the code slightly...

Quoted 7 lines
kernel/wait.c +0 -1
 	finish_wait(wq, &q->wait);
 	return ret;
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Jeff Layton <[email protected]>
#2 lore raw
Quoted 4 lines · Jeff Layton
Quoted 4 lines
kernel/wait.c +0 -0
@@ -333,7 +333,8 @@ int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q,
 		prepare_to_wait(wq, &q->wait, mode);
 		val = q->key.flags;
 		if (atomic_read(val) == 0)
Quoted 8 lines

kernel/wait.c int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q, · line 338

Quoted 4 lines
kernel/wait.c +2 -1
-			ret = (*action)(val);
+			break;
+		ret = (*action)(val);
 	} while (!ret && atomic_read(val) != 0);

nit: can you now eliminate the check for "val" in the while condition? It doesn't look like it harms anything, but eliminating it would probably simplify the code slightly...

Its presence means that we don't have to call prepare_to_wait() again if val became 0.

David

Reviewed-by
#3 lore raw
Quoted 15 lines · On Tue, 23 Jul 2013 17:15:02 +0100 David Howells <[email protected]> wrote:
Quoted 4 lines · Jeff Layton
Quoted 4 lines
kernel/wait.c +0 -0
@@ -333,7 +333,8 @@ int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q,
 		prepare_to_wait(wq, &q->wait, mode);
 		val = q->key.flags;
 		if (atomic_read(val) == 0)
Quoted 8 lines

kernel/wait.c int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q, · line 338

Quoted 4 lines
kernel/wait.c +2 -1
-			ret = (*action)(val);
+			break;
+		ret = (*action)(val);
 	} while (!ret && atomic_read(val) != 0);

nit: can you now eliminate the check for "val" in the while condition? It doesn't look like it harms anything, but eliminating it would probably simplify the code slightly...

Quoted 4 lines

Its presence means that we don't have to call prepare_to_wait() again if val became 0.

David

Ok, and prepare_to_wait involves taking spinlocks, etc...

Got it!