From 29c128cfd29b50e878a0802b7e1f45798f1291ec Mon Sep 17 00:00:00 2001 From: David Collins Date: Thu, 28 May 2020 14:20:35 -0700 Subject: [PATCH] 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 --- drivers/regulator/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 130938b8d048..d177d16b02d8 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -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(®ulator_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);