]> git.ipfire.org Git - thirdparty/linux.git/commit
cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for conditional locks
authorPeter Zijlstra <peterz@infradead.org>
Fri, 11 Jul 2025 23:49:25 +0000 (16:49 -0700)
committerDave Jiang <dave.jiang@intel.com>
Wed, 16 Jul 2025 18:34:36 +0000 (11:34 -0700)
commit857d18f23ab17284d1b6de6f61f4e74958596376
tree1781d9c7f77d0f46130153b787621ab89052a904
parentd0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af
cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for conditional locks

scoped_cond_guard(), automatic cleanup for conditional locks, has a couple
pain points:

* It causes existing straight-line code to be re-indented into a new
  bracketed scope. While this can be mitigated by a new helper function
  to contain the scope, that is not always a comfortable conversion.

* The return code from the conditional lock is tossed in favor of a scheme
  to pass a 'return err;' statement to the macro.

Other attempts to clean this up, to behave more like guard() [1], got hung
up trying to both establish and evaluate the conditional lock in one
statement.

ACQUIRE() solves this by reflecting the result of the condition in the
automatic variable established by the lock CLASS(). The result is
separately retrieved with the ACQUIRE_ERR() helper, effectively a PTR_ERR()
operation.

Link: http://lore.kernel.org/all/Z1LBnX9TpZLR5Dkf@gmail.com
Link: http://patch.msgid.link/20250512105026.GP4439@noisy.programming.kicks-ass.net
Link: http://patch.msgid.link/20250512185817.GA1808@noisy.programming.kicks-ass.net
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Fabio M. De Francesco <fabio.m.de.francesco@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
[djbw: wrap Peter's proposal with changelog and comments]
Co-developed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/20250711234932.671292-2-dan.j.williams@intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
include/linux/cleanup.h
include/linux/mutex.h
include/linux/rwsem.h