diff mbox series

[6/8] backports: rcupdate: Add rcu_replace_pointer

Message ID 20200419171039.17268-7-hauke@hauke-m.de (mailing list archive)
State New, archived
Headers show
Series backports: Update to version 5.6.5 | expand

Commit Message

Hauke Mehrtens April 19, 2020, 5:10 p.m. UTC
rcu_replace_pointer() was added in upstream commit a63fc6b75cca ("rcu:
Upgrade rcu_swap_protected() to rcu_replace_pointer()") and is now used
by the mt76 driver.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 backport/backport-include/linux/rcupdate.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/backport/backport-include/linux/rcupdate.h b/backport/backport-include/linux/rcupdate.h
index db501007..0bbfd615 100644
--- a/backport/backport-include/linux/rcupdate.h
+++ b/backport/backport-include/linux/rcupdate.h
@@ -77,4 +77,24 @@  rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
 } while (0)
 #endif
 
+#ifndef rcu_replace_pointer
+/**
+ * rcu_replace_pointer() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace_pointer(rcu_ptr, ptr, c)				\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+#endif
+
 #endif /* __BACKPORT_LINUX_RCUPDATE_H */