]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
hwmon: (pmbus/core) Protect regulator operations with mutex
authorGuenter Roeck <linux@roeck-us.net>
Sun, 22 Mar 2026 16:12:33 +0000 (09:12 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Wed, 25 Mar 2026 20:32:37 +0000 (13:32 -0700)
commit754bd2b4a084b90b5e7b630e1f423061a9b9b761
tree6b5f585d8743eb88372ecd2d63e505877b4df4b1
parentcd658475e7694d58e1c40dabc1dacf8431ccedb2
hwmon: (pmbus/core) Protect regulator operations with mutex

The regulator operations pmbus_regulator_get_voltage(),
pmbus_regulator_set_voltage(), and pmbus_regulator_list_voltage()
access PMBus registers and shared data but were not protected by
the update_lock mutex. This could lead to race conditions.

However, adding mutex protection directly to these functions causes
a deadlock because pmbus_regulator_notify() (which calls
regulator_notifier_call_chain()) is often called with the mutex
already held (e.g., from pmbus_fault_handler()). If a regulator
callback then calls one of the now-protected voltage functions,
it will attempt to acquire the same mutex.

Rework pmbus_regulator_notify() to utilize a worker function to
send notifications outside of the mutex protection. Events are
stored as atomics in a per-page bitmask and processed by the worker.

Initialize the worker and its associated data during regulator
registration, and ensure it is cancelled on device removal using
devm_add_action_or_reset().

While at it, remove the unnecessary include of linux/of.h.

Cc: Sanman Pradhan <psanman@juniper.net>
Fixes: ddbb4db4ced1b ("hwmon: (pmbus) Add regulator support")
Reviewed-by: Sanman Pradhan <psanman@juniper.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pmbus/pmbus_core.c