From 70cfef26267474f94ff4a988fb45ff78442b1cf4 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 29 Jun 2015 09:04:43 +0900 Subject: regulator: Add lockdep asserts to help detecting locking misuse Add lockdep_assert_held_once() to functions explicitly mentioning that rdev or regulator_list mutex must be held. Using WARN_ONCE shouldn't pollute the dmesg to much. The patch (if CONFIG_LOCKDEP enabled) will show warnings in certain regulators calling regulator_notifier_call_chain() without rdev->mutex held. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Mark Brown --- drivers/regulator/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index c9f72019bd68..68b616580533 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -640,6 +640,8 @@ static int drms_uA_update(struct regulator_dev *rdev) int current_uA = 0, output_uV, input_uV, err; unsigned int mode; + lockdep_assert_held_once(&rdev->mutex); + /* * first check to see if we can set modes at all, otherwise just * tell the consumer everything is OK. @@ -760,6 +762,8 @@ static int suspend_set_state(struct regulator_dev *rdev, /* locks held by caller */ static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) { + lockdep_assert_held_once(&rdev->mutex); + if (!rdev->constraints) return -EINVAL; @@ -1587,6 +1591,8 @@ static void _regulator_put(struct regulator *regulator) if (regulator == NULL || IS_ERR(regulator)) return; + lockdep_assert_held_once(®ulator_list_mutex); + rdev = regulator->rdev; debugfs_remove_recursive(regulator->debugfs); @@ -1965,6 +1971,8 @@ static int _regulator_enable(struct regulator_dev *rdev) { int ret; + lockdep_assert_held_once(&rdev->mutex); + /* check voltage and requested load before enabling */ if (rdev->constraints && (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) @@ -2065,6 +2073,8 @@ static int _regulator_disable(struct regulator_dev *rdev) { int ret = 0; + lockdep_assert_held_once(&rdev->mutex); + if (WARN(rdev->use_count <= 0, "unbalanced disables for %s\n", rdev_get_name(rdev))) return -EIO; @@ -2143,6 +2153,8 @@ static int _regulator_force_disable(struct regulator_dev *rdev) { int ret = 0; + lockdep_assert_held_once(&rdev->mutex); + ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | REGULATOR_EVENT_PRE_DISABLE, NULL); if (ret & NOTIFY_STOP_MASK) @@ -3439,6 +3451,8 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); int regulator_notifier_call_chain(struct regulator_dev *rdev, unsigned long event, void *data) { + lockdep_assert_held_once(&rdev->mutex); + _notifier_call_chain(rdev, event, data); return NOTIFY_DONE; -- cgit v1.2.3 From 7cd71c3ba166913a0afb8ac0d6bd5d2730fea6df Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 7 Aug 2015 13:00:35 +0100 Subject: regulator: core: Drop regulator_list_mutex when we're done with it on remove When removing a regulator we hold regulator_list_mutex in order to ensure the regualtor doesn't become removed again. However we only need to protect the list until we remove the regulator from the list so move the unlock earlier to reduce the locked region. Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 68b616580533..62e4f3bd5783 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3827,11 +3827,11 @@ void regulator_unregister(struct regulator_dev *rdev) WARN_ON(rdev->open_count); unset_regulator_supplies(rdev); list_del(&rdev->list); + mutex_unlock(®ulator_list_mutex); kfree(rdev->constraints); regulator_ena_gpio_free(rdev); of_node_put(rdev->dev.of_node); device_unregister(&rdev->dev); - mutex_unlock(®ulator_list_mutex); } EXPORT_SYMBOL_GPL(regulator_unregister); -- cgit v1.2.3 From d3fb9800146b7ad96b7604755c1a943fe1abbde2 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 13 Aug 2015 18:09:49 +0530 Subject: regulator: core: Spelling fix Trivial spell fix, s/succesfully/successfully. Signed-off-by: Viresh Kumar Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 62e4f3bd5783..999a94b9735e 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2723,7 +2723,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) goto out; /* If we're trying to set a range that overlaps the current voltage, - * return succesfully even though the regulator does not support + * return successfully even though the regulator does not support * changing the voltage. */ if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { -- cgit v1.2.3 From 93576842718edf302b03f30b9915d3e704b0c78a Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Mon, 17 Aug 2015 12:30:58 +0530 Subject: regulator: core: Use IS_ERR_OR_NULL() Use IS_ERR_OR_NULL() rather than open coding it. Signed-off-by: Viresh Kumar Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 999a94b9735e..5d61eb8f2a79 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1588,7 +1588,7 @@ static void _regulator_put(struct regulator *regulator) { struct regulator_dev *rdev; - if (regulator == NULL || IS_ERR(regulator)) + if (IS_ERR_OR_NULL(regulator)) return; lockdep_assert_held_once(®ulator_list_mutex); -- cgit v1.2.3 From 099982fac0f3e884ed4af2178d4dcded69e0042e Mon Sep 17 00:00:00 2001 From: Archit Taneja Date: Fri, 28 Aug 2015 16:22:18 +0530 Subject: regulator: core: use debug level print in regulator_check_drms When calling regulator_set_load, regulator_check_drms prints and returns an error if the regulator device's flag REGULATOR_CHANGE_DRMS isn't set. drms_uA_update, however, bails out without reporting an error. Replace the error print with a debug level print so that we don't get such prints when the underlying regulator doesn't support DRMS. Signed-off-by: Archit Taneja Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 5d61eb8f2a79..22e276f7e72f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -295,7 +295,7 @@ static int regulator_check_drms(struct regulator_dev *rdev) return -ENODEV; } if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { - rdev_err(rdev, "operation not allowed\n"); + rdev_dbg(rdev, "operation not allowed\n"); return -EPERM; } return 0; -- cgit v1.2.3