diff mbox series

[5/8] backports: rcupdate.h: Add rcu_swap_protected()

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

Commit Message

Hauke Mehrtens March 20, 2020, 11:39 p.m. UTC
Backport rcu_swap_protected() from upstream Linux commit 26e3e3cb0560
("scsi: rcu: Introduce rcu_swap_protected()"). This is used by the mt76
driver.

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

Patch

diff --git a/backport/backport-include/linux/rcupdate.h b/backport/backport-include/linux/rcupdate.h
index cec4b3e8..db501007 100644
--- a/backport/backport-include/linux/rcupdate.h
+++ b/backport/backport-include/linux/rcupdate.h
@@ -59,4 +59,22 @@  rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
 }
 #endif /* < 4.20 */
 
+#ifndef rcu_swap_protected
+/**
+ * rcu_swap_protected() - swap an RCU and a regular pointer
+ * @rcu_ptr: RCU pointer
+ * @ptr: regular pointer
+ * @c: the conditions under which the dereference will take place
+ *
+ * Perform swap(@rcu_ptr, @ptr) where @rcu_ptr is an RCU-annotated pointer and
+ * @c is the argument that is passed to the rcu_dereference_protected() call
+ * used to read that pointer.
+ */
+#define rcu_swap_protected(rcu_ptr, ptr, c) do {			\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	(ptr) = __tmp;							\
+} while (0)
+#endif
+
 #endif /* __BACKPORT_LINUX_RCUPDATE_H */