]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: Support guard() and scoped_guard for subsystem locks
authorGuenter Roeck <linux@roeck-us.net>
Wed, 13 May 2026 14:14:33 +0000 (07:14 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 9 Jun 2026 15:23:00 +0000 (08:23 -0700)
Add support for guard() and scoped_guard() for the hwmon subsystem lock
to simplify its use.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Documentation/hwmon/hwmon-kernel-api.rst
include/linux/hwmon.h

index 1d7f1397a827445acfcda317207efc55d3d2ec39..9fcde32a140df6d7e7beb54041fe2a9aecaf1f0f 100644 (file)
@@ -85,9 +85,10 @@ removal.
 When using ``[devm_]hwmon_device_register_with_info()`` to register the
 hardware monitoring device, accesses using the associated access functions
 are serialised by the hardware monitoring core. If a driver needs locking
-for other functions such as interrupt handlers or for attributes which are
-fully implemented in the driver, hwmon_lock() and hwmon_unlock() can be used
-to ensure that calls to those functions are serialized.
+for other functions such as interrupt handlers, attributes which are fully
+implemented in the driver, or debugfs functions, hwmon_lock() and hwmon_unlock()
+can be used to ensure that calls to those functions are serialized. Those
+functions also support guard() and scoped_guard() variants.
 
 Using devm_hwmon_device_register_with_info()
 --------------------------------------------
index 301a83afbd6636101f53fc49b151eb534426f212..f5330e7ae247cc1159e5808725a965d116a49450 100644 (file)
@@ -13,6 +13,7 @@
 #define _HWMON_H_
 
 #include <linux/bitops.h>
+#include <linux/cleanup.h>
 
 struct device;
 struct attribute_group;
@@ -495,6 +496,8 @@ char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
 void hwmon_lock(struct device *dev);
 void hwmon_unlock(struct device *dev);
 
+DEFINE_GUARD(hwmon_lock, struct device *, hwmon_lock(_T), hwmon_unlock(_T))
+
 /**
  * hwmon_is_bad_char - Is the char invalid in a hwmon name
  * @ch: the char to be considered