Skip to content

Commit 6303f3e

Browse files
digetxbroonie
authored andcommitted
regulator: core: Decouple regulators on regulator_unregister()
Regulators shall be uncoupled if one of the couples disappear. Signed-off-by: Dmitry Osipenko <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 85254bc commit 6303f3e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

drivers/regulator/core.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,6 +4518,43 @@ static void regulator_resolve_coupling(struct regulator_dev *rdev)
45184518
}
45194519
}
45204520

4521+
static void regulator_remove_coupling(struct regulator_dev *rdev)
4522+
{
4523+
struct coupling_desc *__c_desc, *c_desc = &rdev->coupling_desc;
4524+
struct regulator_dev *__c_rdev, *c_rdev;
4525+
unsigned int __n_coupled, n_coupled;
4526+
int i, k;
4527+
4528+
n_coupled = c_desc->n_coupled;
4529+
4530+
for (i = 1; i < n_coupled; i++) {
4531+
c_rdev = c_desc->coupled_rdevs[i];
4532+
4533+
if (!c_rdev)
4534+
continue;
4535+
4536+
regulator_lock(c_rdev);
4537+
4538+
__c_desc = &c_rdev->coupling_desc;
4539+
__n_coupled = __c_desc->n_coupled;
4540+
4541+
for (k = 1; k < __n_coupled; k++) {
4542+
__c_rdev = __c_desc->coupled_rdevs[k];
4543+
4544+
if (__c_rdev == rdev) {
4545+
__c_desc->coupled_rdevs[k] = NULL;
4546+
__c_desc->n_resolved--;
4547+
break;
4548+
}
4549+
}
4550+
4551+
regulator_unlock(c_rdev);
4552+
4553+
c_desc->coupled_rdevs[i] = NULL;
4554+
c_desc->n_resolved--;
4555+
}
4556+
}
4557+
45214558
static int regulator_init_coupling(struct regulator_dev *rdev)
45224559
{
45234560
int n_phandles;
@@ -4776,6 +4813,7 @@ void regulator_unregister(struct regulator_dev *rdev)
47764813
debugfs_remove_recursive(rdev->debugfs);
47774814
flush_work(&rdev->disable_work.work);
47784815
WARN_ON(rdev->open_count);
4816+
regulator_remove_coupling(rdev);
47794817
unset_regulator_supplies(rdev);
47804818
list_del(&rdev->list);
47814819
regulator_ena_gpio_free(rdev);

0 commit comments

Comments
 (0)