diff mbox series

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

Message ID 20240626230241.6765-1-ansuelsmth@gmail.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series [net-next,RFC,1/2] net: mdio: implement mdio_mutex_nested guard() variant | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
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: 845 this patch: 845
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 870 this patch: 870
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: 1454 this patch: 1454
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 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 June 26, 2024, 11:02 p.m. UTC
Implement mdio_mutex_nested guard() variant.

guard() compes from the cleanup.h API that define handy class to
define the lifecycle of a critical section.

Many driver makes use of the mutex_lock_nested()/mutex_unlock() hence it
might be sensible to provide a variant of the generic guard(mutex),
guard(mdio_mutex_nested) to also support drivers that use
mutex_lock_nested with MDIO_MUTEX_NESTED.

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

Comments

Markus Elfring June 27, 2024, 1:52 p.m. UTC | #1
> Implement mdio_mutex_nested guard() variant.

I find the idea generally helpful.
The concrete implementation needs further clarifications.


> guard() compes from the cleanup.h API that define handy class to

          comes?                             defines?


> define the lifecycle of a critical section.

  handle?


> Many driver makes use of the mutex_lock_nested()/mutex_unlock() hence it

  Several drivers use?                                            function call pair.

Would you like to clarify any application statistics another bit?
https://elixir.bootlin.com/linux/v6.10-rc5/A/ident/mutex_lock_nested


> might be sensible to provide a variant of the generic guard(mutex),

  Hence it is?                                                      :


> guard(mdio_mutex_nested) to also support drivers that use
> mutex_lock_nested with MDIO_MUTEX_NESTED.

Another wording suggestion:
  guard(mdio_mutex_nested) so that drivers can be better supported
  with the call variant “mutex_lock_nested(…, MDIO_MUTEX_NESTED)”.


…
> +++ b/include/linux/mdio.h
> @@ -8,6 +8,8 @@
>
>  #include <uapi/linux/mdio.h>
>  #include <linux/bitfield.h>
> +#include <linux/cleanup.h>

I suggest to omit this preprocessing directive here.


> +#include <linux/mutex.h>
>  #include <linux/mod_devicetable.h>
…

Further information is included as possibly needed.
https://elixir.bootlin.com/linux/v6.10-rc5/source/include/linux/mutex.h#L22

How reasonable is the added header file dependency so far?


Under which circumstances can remaining change resistance be adjusted
for further benefits from applications of scope-based resource management?

Regards,
Markus
diff mbox series

Patch

diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 68f8d2e970d4..f13a02d05eb2 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -8,6 +8,8 @@ 
 
 #include <uapi/linux/mdio.h>
 #include <linux/bitfield.h>
+#include <linux/cleanup.h>
+#include <linux/mutex.h>
 #include <linux/mod_devicetable.h>
 
 struct gpio_desc;
@@ -25,6 +27,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;