diff mbox series

[net-next,RFC,1/4] net: mdio: implement mdio_mutex_nested guard() variant

Message ID 20241021130209.15660-2-ansuelsmth@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: Add Airoha AN8855 support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 157 (+0) this patch: 157 (+0)
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 22 this patch: 22
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 538 this patch: 538
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 41 this patch: 41
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi Oct. 21, 2024, 1:01 p.m. UTC
Implement mdio_mutex_nested guard() variant.

guard() comes from the cleanup.h API that defines handy class to
handle the lifecycle of a critical section.

Several drivers use of the mutex_lock_nested()/mutex_unlock() function
call pair hence it is sensible to provide a variant of the generic
guard(mutex), guard(mdio_mutex_nested) so that drivers can be better
supported with the call variant "mutex_lock_nested(..., MDIO_MUTEX_NESTED)"

Example usage:

guard(mutex_lock_nested)(&bus->mdio_lock)
scoped_guard(mutex_lock_nested, &bus->mdio_lock) { ... }

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 include/linux/mdio.h | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index efeca5bd7600..3f0691dee46a 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -8,6 +8,7 @@ 
 
 #include <uapi/linux/mdio.h>
 #include <linux/bitfield.h>
+#include <linux/mutex.h>
 #include <linux/mod_devicetable.h>
 
 struct gpio_desc;
@@ -25,6 +26,9 @@  enum mdio_mutex_lock_class {
 	MDIO_MUTEX_NESTED,
 };
 
+DEFINE_GUARD(mdio_mutex_nested, struct mutex *,
+	     mutex_lock_nested(_T, MDIO_MUTEX_NESTED), mutex_unlock(_T))
+
 struct mdio_device {
 	struct device dev;