[PATCH] lib/plist.c: Enforce memory ordering in plist_check_list

I Hsin Cheng posted 1 patch 1 year, 8 months ago
lib/plist.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] lib/plist.c: Enforce memory ordering in plist_check_list
Posted by I Hsin Cheng 1 year, 8 months ago
There exist an iteration over a plist in the function plist_check_list,
and memory dependency exists between variables "prev", "next" and
"prev->next". Consider plist is used scheduling subsystem, we should
guarantee the memory order between multiple processors.

Using macro "WRITE_ONCE()" can help us to ensure the memory ordering as
it was stated in "/Documentation/memory-barriers.txt".

Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
 lib/plist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/plist.c b/lib/plist.c
index 0d86ed7a7..2e51829d3 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -47,8 +47,8 @@ static void plist_check_list(struct list_head *top)
 
 	plist_check_prev_next(top, prev, next);
 	while (next != top) {
-		prev = next;
-		next = prev->next;
+		WRITE_ONCE(prev, next);
+		WRITE_ONCE(next, prev->next);
 		plist_check_prev_next(top, prev, next);
 	}
 }
-- 
2.34.1