[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <0e37d1f09718a6ab9204b367ff528ab02df25ac7.1692484240.git.mirq-linux@rere.qmqm.pl>
Date: Sun, 20 Aug 2023 00:46:08 +0200
From: Michał Mirosław <mirq-linux@...e.qmqm.pl>
To: Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>
Cc: linux-kernel@...r.kernel.org, Dmitry Osipenko <digetx@...il.com>,
Douglas Anderson <dianders@...omium.org>
Subject: [PATCH 1/6] regulator: core: simplify regulator_lock_nested()
`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@...e.qmqm.pl>
---
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
Powered by blists - more mailing lists