[RFC,v2,1/2] regulator: core: Consistently set mutex_owner when using ww_mutex_lock_slow()

Message ID 20230329143317.RFC.v2.1.I4e9d433ea26360c06dd1381d091c82bb1a4ce843@changeid
State New
Headers
Series [RFC,v2,1/2] regulator: core: Consistently set mutex_owner when using ww_mutex_lock_slow() |

Commit Message

Doug Anderson March 29, 2023, 9:33 p.m. UTC
  When a codepath locks a rdev using ww_mutex_lock_slow() directly then
that codepath is responsible for incrementing the "ref_cnt" and also
setting the "mutex_owner" to "current".

The regulator core consistently got that right for "ref_cnt" but
didn't always get it right for "mutex_owner". Let's fix this.

It's unlikely that this truly matters because the "mutex_owner" is
only needed if we're going to do subsequent locking of the same
rdev. However, even though it's not truly needed it seems less
surprising if we consistently set "mutex_owner" properly.

Fixes: f8702f9e4aa7 ("regulator: core: Use ww_mutex for regulators locking")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

Changes in v2:
- "Consistently set mutex_owner when using ww_mutex_lock_slow()" new for v2.

 drivers/regulator/core.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Mark Brown April 6, 2023, 3:03 p.m. UTC | #1
On Wed, 29 Mar 2023 14:33:53 -0700, Douglas Anderson wrote:
> When a codepath locks a rdev using ww_mutex_lock_slow() directly then
> that codepath is responsible for incrementing the "ref_cnt" and also
> setting the "mutex_owner" to "current".
> 
> The regulator core consistently got that right for "ref_cnt" but
> didn't always get it right for "mutex_owner". Let's fix this.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/2] regulator: core: Consistently set mutex_owner when using ww_mutex_lock_slow()
      commit: b83a1772be854f87602de14726737d3e5b06e1f4
[2/2] regulator: core: Avoid lockdep reports when resolving supplies
      commit: cba6cfdc7c3f1516f0d08ddfb24e689af0932573

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
  

Patch

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 1490eb40c973..9a13240f3084 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -334,6 +334,7 @@  static void regulator_lock_dependent(struct regulator_dev *rdev,
 			ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx);
 			old_contended_rdev = new_contended_rdev;
 			old_contended_rdev->ref_cnt++;
+			old_contended_rdev->mutex_owner = current;
 		}
 
 		err = regulator_lock_recursive(rdev,
@@ -6048,6 +6049,7 @@  static void regulator_summary_lock(struct ww_acquire_ctx *ww_ctx)
 			ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx);
 			old_contended_rdev = new_contended_rdev;
 			old_contended_rdev->ref_cnt++;
+			old_contended_rdev->mutex_owner = current;
 		}
 
 		err = regulator_summary_lock_all(ww_ctx,