Skip to contentSkip to conversation

list: Remove unnecessary WRITE_ONCE()

PATCH In review Alan Huang 2 participants 4 messages Jun 19, 2023 – Jun 21, 2023

lore
Share & tools
lore

Alan Huang

author
#0 lore raw

PATCH 1/1 list: Remove unnecessary WRITE_ONCE()

Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added various WRITE_ONCE() to pair with the READ_ONCE() in hlist_unhashed_lockless(), but there is no need to protect ->next with WRITE_ONCE(). Therefore, this commit removes those unnecessary WRITE_ONCE().

---
 include/linux/list.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/list.h +4 -4
index f10344dbad..ac366958ea 100644
@@ -940,7 +940,7 @@ static inline void hlist_del_init(struct hlist_node *n)
 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 {
 	struct hlist_node *first = h->first;
-	WRITE_ONCE(n->next, first);
+	n->next = first;
 	if (first)
 		WRITE_ONCE(first->pprev, &n->next);
 	WRITE_ONCE(h->first, n);
@@ -956,7 +956,7 @@ static inline void hlist_add_before(struct hlist_node *n,
 				    struct hlist_node *next)
 {
 	WRITE_ONCE(n->pprev, next->pprev);
-	WRITE_ONCE(n->next, next);
+	n->next = next;
 	WRITE_ONCE(next->pprev, &n->next);
 	WRITE_ONCE(*(n->pprev), n);
 }
@@ -969,8 +969,8 @@ static inline void hlist_add_before(struct hlist_node *n,
 static inline void hlist_add_behind(struct hlist_node *n,
 				    struct hlist_node *prev)
 {
-	WRITE_ONCE(n->next, prev->next);
-	WRITE_ONCE(prev->next, n);
+	n->next = prev->next;
+	prev->next = n;
 	WRITE_ONCE(n->pprev, &prev->next);
 
 	if (n->next)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 6 lines · Alan Huang

Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added various WRITE_ONCE() to pair with the READ_ONCE() in hlist_unhashed_lockless(), but there is no need to protect ->next with WRITE_ONCE(). Therefore, this commit removes those unnecessary WRITE_ONCE().

Why are they unnecessary ?
They seem just fine to me.
Please elaborate.

author
#2 lore raw
Quoted 5 lines

2023年6月19日 19:02,Eric Dumazet <[email protected]> 写道:

Quoted 1 line · Alan Huang
Quoted 7 lines
Quoted 5 lines

Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added various WRITE_ONCE() to pair with the READ_ONCE() in hlist_unhashed_lockless(), but there is no need to protect ->next with WRITE_ONCE(). Therefore, this commit removes those unnecessary WRITE_ONCE().

Why are they unnecessary ?

There is no reader locklessly read ->next.

These functions are protected by something like spin_lock, only the thread running the function can access ->next.

Quoted 2 lines

They seem just fine to me.
Please elaborate.

author
#3 lore raw
In reply to Alan Huang

Hi Paul,

Looks like you missed this one?

Thanks,
Alan

Quoted 49 lines

2023年6月19日 17:03,Alan Huang <[email protected]> 写道:

Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added various WRITE_ONCE() to pair with the READ_ONCE() in hlist_unhashed_lockless(), but there is no need to protect ->next with WRITE_ONCE(). Therefore, this commit removes those unnecessary WRITE_ONCE().

---
include/linux/list.h | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/list.h +4 -4
index f10344dbad..ac366958ea 100644
@@ -940,7 +940,7 @@ static inline void hlist_del_init(struct hlist_node *n)
 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 {
 struct hlist_node *first = h->first;
- WRITE_ONCE(n->next, first);
+ n->next = first;
 if (first)
 WRITE_ONCE(first->pprev, &n->next);
 WRITE_ONCE(h->first, n);
@@ -956,7 +956,7 @@ static inline void hlist_add_before(struct hlist_node *n,
   struct hlist_node *next)
 {
 WRITE_ONCE(n->pprev, next->pprev);
- WRITE_ONCE(n->next, next);
+ n->next = next;
 WRITE_ONCE(next->pprev, &n->next);
 WRITE_ONCE(*(n->pprev), n);
 }
@@ -969,8 +969,8 @@ static inline void hlist_add_before(struct hlist_node *n,
 static inline void hlist_add_behind(struct hlist_node *n,
   struct hlist_node *prev)
 {
- WRITE_ONCE(n->next, prev->next);
- WRITE_ONCE(prev->next, n);
+ n->next = prev->next;
+ prev->next = n;
 WRITE_ONCE(n->pprev, &prev->next);
 
 if (n->next)
Signature · 1 line
2.34.1