[PATCH 1/6] regulator: core: simplify regulator_lock_nested()
From: Michał Mirosław
Date: Sat Aug 19 2023 - 20:27:37 EST
`lock` is only false when the `rdev` is already locked and the owner is
`current`. In this case `ret` is always zero. By removing `lock`, we
thus remove `mutex_owner` write avoidance, but make the code flow more
understandable.
Signed-off-by: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
---
drivers/regulator/core.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d8e1caaf207e..215b721e5cd4 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -141,27 +141,19 @@ static bool regulator_ops_is_valid(struct regulator_dev *rdev, int ops)
static inline int regulator_lock_nested(struct regulator_dev *rdev,
struct ww_acquire_ctx *ww_ctx)
{
- bool lock = false;
int ret = 0;
mutex_lock(®ulator_nesting_mutex);
if (!ww_mutex_trylock(&rdev->mutex, ww_ctx)) {
- if (rdev->mutex_owner == current)
- rdev->ref_cnt++;
- else
- lock = true;
-
- if (lock) {
+ if (rdev->mutex_owner != current) {
mutex_unlock(®ulator_nesting_mutex);
ret = ww_mutex_lock(&rdev->mutex, ww_ctx);
mutex_lock(®ulator_nesting_mutex);
}
- } else {
- lock = true;
}
- if (lock && ret != -EDEADLK) {
+ if (ret != -EDEADLK) {
rdev->ref_cnt++;
rdev->mutex_owner = current;
}
--
2.39.2