regulator: core: avoid deadlock in QTI addition to regulator_unregister()

regulator_unregister() calls rdev_free_qti_debugfs() with the
regulator_list_mutex held.  rdev_free_qti_debugfs() then calls
regulator_put() which attempts to lock regulator_list_mutex again.
This leads to deadlock.

Modify regulator_unregister() and rdev_free_qti_debugfs() so that
mutex deadlock cannot occur.

Change-Id: I12bb4c704f7d9332e790c707aba854e224474bdb
Signed-off-by: David Collins <collinsd@codeaurora.org>
This commit is contained in:
David Collins 2020-05-28 14:20:35 -07:00
commit 29c128cfd2

View file

@ -5045,9 +5045,8 @@ DEFINE_DEBUGFS_ATTRIBUTE(reg_set_load_fops, reg_debug_mode_get,
static void rdev_free_qti_debugfs(struct regulator_dev *rdev)
{
if (!IS_ERR_OR_NULL(rdev)) {
if (rdev->debug_consumer)
rdev->debug_consumer->debugfs = NULL;
regulator_put(rdev->debug_consumer);
rdev->debug_consumer = NULL;
}
}
@ -5658,11 +5657,11 @@ void regulator_unregister(struct regulator_dev *rdev)
}
flush_work(&rdev->disable_work.work);
rdev_free_qti_debugfs(rdev);
mutex_lock(&regulator_list_mutex);
debugfs_remove_recursive(rdev->debugfs);
rdev_free_qti_debugfs(rdev);
WARN_ON(rdev->open_count);
regulator_remove_coupling(rdev);
unset_regulator_supplies(rdev);