Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rcu: Don't return a value from rcu_assign_pointer()

Quoting Paul [1]:

"Given that a quick (and perhaps error-prone) search of the uses
of rcu_assign_pointer() in v5.1 didn't find a single use of the
return value, let's please instead change the documentation and
implementation to eliminate the return value."

[1] https://lkml.kernel.org/r/20190523135013.GL28207@linux.ibm.com

Signed-off-by: Andrea Parri <andrea.parri@amarulasolutions.com>
Cc: "Paul E. McKenney" <paulmck@linux.ibm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: rcu@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com>

authored by

Andrea Parri and committed by
Paul E. McKenney
9129b017 6da9f775

+9 -10
+4 -4
Documentation/RCU/whatisRCU.txt
··· 212 212 213 213 rcu_assign_pointer() 214 214 215 - typeof(p) rcu_assign_pointer(p, typeof(p) v); 215 + void rcu_assign_pointer(p, typeof(p) v); 216 216 217 217 Yes, rcu_assign_pointer() -is- implemented as a macro, though it 218 218 would be cool to be able to declare a function in this manner. ··· 220 220 221 221 The updater uses this function to assign a new value to an 222 222 RCU-protected pointer, in order to safely communicate the change 223 - in value from the updater to the reader. This function returns 224 - the new value, and also executes any memory-barrier instructions 225 - required for a given CPU architecture. 223 + in value from the updater to the reader. This macro does not 224 + evaluate to an rvalue, but it does execute any memory-barrier 225 + instructions required for a given CPU architecture. 226 226 227 227 Perhaps just as important, it serves to document (1) which 228 228 pointers are protected by RCU and (2) the point at which a
+2 -3
include/linux/rcupdate.h
··· 367 367 * other macros that it invokes. 368 368 */ 369 369 #define rcu_assign_pointer(p, v) \ 370 - ({ \ 370 + do { \ 371 371 uintptr_t _r_a_p__v = (uintptr_t)(v); \ 372 372 rcu_check_sparse(p, __rcu); \ 373 373 \ ··· 375 375 WRITE_ONCE((p), (typeof(p))(_r_a_p__v)); \ 376 376 else \ 377 377 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \ 378 - _r_a_p__v; \ 379 - }) 378 + } while (0) 380 379 381 380 /** 382 381 * rcu_swap_protected() - swap an RCU and a regular pointer
+2 -2
tools/include/linux/rcu.h
··· 19 19 return false; 20 20 } 21 21 22 - #define rcu_assign_pointer(p, v) ((p) = (v)) 23 - #define RCU_INIT_POINTER(p, v) p=(v) 22 + #define rcu_assign_pointer(p, v) do { (p) = (v); } while (0) 23 + #define RCU_INIT_POINTER(p, v) do { (p) = (v); } while (0) 24 24 25 25 #endif
+1 -1
tools/testing/radix-tree/linux/rcupdate.h
··· 7 7 #define rcu_dereference_raw(p) rcu_dereference(p) 8 8 #define rcu_dereference_protected(p, cond) rcu_dereference(p) 9 9 #define rcu_dereference_check(p, cond) rcu_dereference(p) 10 - #define RCU_INIT_POINTER(p, v) (p) = (v) 10 + #define RCU_INIT_POINTER(p, v) do { (p) = (v); } while (0) 11 11 12 12 #endif