[PATCH] stop_machine: fix race with return value (fixes Bug #11989)

From: Rusty Russell
Date: Sun Nov 16 2008 - 16:52:33 EST


Bug #11989: Suspend failure on NForce4-based boards due to chanes in stop_machine

We should not access active.fnret outside the lock; in theory the next
stop_machine could overwrite it.

Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Tested-by: "Rafael J. Wysocki" <rjw@xxxxxxx>
---
kernel/stop_machine.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff -r d7c9a15da615 kernel/stop_machine.c
--- a/kernel/stop_machine.c Mon Nov 10 09:47:45 2008 +1100
+++ b/kernel/stop_machine.c Tue Nov 11 23:19:47 2008 +1030
@@ -112,7 +112,7 @@
int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)
{
struct work_struct *sm_work;
- int i;
+ int i, ret;

/* Set up initial state. */
mutex_lock(&lock);
@@ -137,8 +137,9 @@
/* This will release the thread on our CPU. */
put_cpu();
flush_workqueue(stop_machine_wq);
+ ret = active.fnret;
mutex_unlock(&lock);
- return active.fnret;
+ return ret;
}

int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)

N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i