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 New, archived
Headers show
Series net: dsa: Add Airoha AN8855 support | expand

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;