hwmon: Serialize accesses in hwmon core
authorGuenter Roeck <linux@roeck-us.net>
Thu, 5 Jun 2025 23:23:57 +0000 (16:23 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 8 Sep 2025 13:24:50 +0000 (06:24 -0700)
commit3ad2a7b9b15d5072139a20be84adb36776eb6c9b
tree1d73ea66f97741465d49c16bfc61213e2b9e00ea
parent90bad684e9ac5ae435c2715fab36f6799849e800
hwmon: Serialize accesses in hwmon core

Implement locking in the hardware monitoring core for drivers using
the _with_info() API functions.

Most hardware monitoring drivers need to support locking to protect
against parallel accesses from userspace. With older API functions, such
locking had to be implemented in the driver code since sysfs attributes
were created by the driver. However, the _with_info() API creates sysfs
attributes in the hardware monitoring core. This makes it easy to move
the locking primitives into that code. This has the benefit of simplifying
driver code while at the same time reducing the risk of incomplete of bad
locking implementations in hardware monitoring drivers.

While this means that all accesses are forced to be synchronized, this
has little if any practical impact since accesses are expected to be low
frequency and are typically synchronized from userspace anyway since
only a single process is accessing the data. On top of that, many drivers
use regmap, which also has its own locking scheme and already serializes
accesses.

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