lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <172992812675.1442.16190431929459104566.tip-bot2@tip-bot2>
Date: Sat, 26 Oct 2024 07:35:26 -0000
From: "tip-bot2 for David Lechner" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: David Lechner <dlechner@...libre.com>,
 "Fabio M. De Francesco" <fabio.m.de.francesco@...ux.intel.com>,
 "Peter Zijlstra (Intel)" <peterz@...radead.org>,
 Dan Williams <dan.j.williams@...el.com>, x86@...nel.org,
 linux-kernel@...r.kernel.org
Subject: [tip: locking/core] cleanup: Add conditional guard helper

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     36c2cf88808d47e926d11b98734f154fe4a9f50f
Gitweb:        https://git.kernel.org/tip/36c2cf88808d47e926d11b98734f154fe4a9f50f
Author:        David Lechner <dlechner@...libre.com>
AuthorDate:    Tue, 01 Oct 2024 17:30:18 -05:00
Committer:     Peter Zijlstra <peterz@...radead.org>
CommitterDate: Fri, 25 Oct 2024 10:01:51 +02:00

cleanup: Add conditional guard helper

Add a new if_not_guard() macro to cleanup.h for handling
conditional guards such as mutext_trylock().

This is more ergonomic than scoped_guard() for most use cases.
Instead of hiding the error handling statement in the macro args, it
works like a normal if statement and allow the error path to be indented
while the normal code flow path is not indented. And it avoid unwanted
side-effect from hidden for loop in scoped_guard().

Signed-off-by: David Lechner <dlechner@...libre.com>
Co-developed-by: Fabio M. De Francesco <fabio.m.de.francesco@...ux.intel.com>
Signed-off-by: Fabio M. De Francesco <fabio.m.de.francesco@...ux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Reviewed-by: Dan Williams <dan.j.williams@...el.com>
Link: https://lkml.kernel.org/r/20241001-cleanup-if_not_cond_guard-v1-1-7753810b0f7a@baylibre.com
---
 include/linux/cleanup.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index 0cc66f8..e859f79 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -273,6 +273,12 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \
  *	an anonymous instance of the (guard) class, not recommended for
  *	conditional locks.
  *
+ * if_not_guard(name, args...) { <error handling> }:
+ *	convenience macro for conditional guards that calls the statement that
+ *	follows only if the lock was not acquired (typically an error return).
+ *
+ *	Only for conditional locks.
+ *
  * scoped_guard (name, args...) { }:
  *	similar to CLASS(name, scope)(args), except the variable (with the
  *	explicit name 'scope') is declard in a for-loop such that its scope is
@@ -343,6 +349,15 @@ _label:									\
 
 #define scoped_cond_guard(_name, _fail, args...)	\
 	__scoped_cond_guard(_name, _fail, __UNIQUE_ID(label), args)
+
+#define __if_not_guard(_name, _id, args...)		\
+	BUILD_BUG_ON(!__is_cond_ptr(_name));		\
+	CLASS(_name, _id)(args);			\
+	if (!__guard_ptr(_name)(&_id))
+
+#define if_not_guard(_name, args...) \
+	__if_not_guard(_name, __UNIQUE_ID(guard), args)
+
 /*
  * Additional helper macros for generating lock guards with types, either for
  * locks that don't have a native type (eg. RCU, preempt) or those that need a

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ