regulator: core: Make locks re-entrant
authorMaciej Purski <m.purski@samsung.com>
Mon, 23 Apr 2018 14:33:37 +0000 (16:33 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 17 May 2018 07:05:03 +0000 (16:05 +0900)
commit66cf9a7e0192734c1c94751e628bd075be62cff4
treebd032804bb4f2cd5c17ab66c3da7b6e69ace45b8
parent0369e02b75e6381f892e3bd45f1d8d6330d855fb
regulator: core: Make locks re-entrant

Setting voltage, enabling/disabling regulators requires operations on
all regulators related with the regulator being changed. Therefore,
all of them should be locked for the whole operation. With the current
locking implementation, adding additional dependency (regulators
coupling) causes deadlocks in some cases.

Introduce a possibility to attempt to lock a mutex multiple times
by the same task without waiting on a mutex. This should handle all
reasonable coupling-supplying combinations, especially when two coupled
regulators share common supplies. The only situation that should be
forbidden is simultaneous coupling and supplying between a pair of
regulators.

The idea is based on clk core.

Signed-off-by: Maciej Purski <m.purski@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c
include/linux/regulator/driver.h