From nobody Fri Dec 19 04:03:18 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 442D0C83F1B for ; Wed, 30 Aug 2023 19:03:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240440AbjH3TBe (ORCPT ); Wed, 30 Aug 2023 15:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343954AbjH3Rfh (ORCPT ); Wed, 30 Aug 2023 13:35:37 -0400 Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9551D1A3 for ; Wed, 30 Aug 2023 10:35:34 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RbWfF1KmZzgk; Wed, 30 Aug 2023 19:35:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1693416933; bh=FBO3C/ZT0gXV582lOwqaqYNAxfqDw70mVXC++i5rfZQ=; h=Date:In-Reply-To:References:Subject:From:To:Cc:From; b=V0rJTCM40625GgmDxlSvUOLWaZOLLW+/FF4+z4VjKTlAulr35h8dJbrJr5VbfoQn2 SLoU4Qsmqt8wWw/svk6m6PpYOepC8Eesrt9aHTJRPWJ7FM9YyyaQbLyF3vknwuGEyG 8/ex66OV96WAAsHj2PYDAE+NlFUXnc5LVNjFMtjh0TF5tPHtiVcnGBRQbL7utEB1rF Ly1Hv3S5evsQJWGbkTDjDwjHZJT+TPnxW5ceLDrFdJU5PcXjJRAAsaCJyYh9UjiCR9 MxUF5FQEMTmZVLIbS6sXAt2PDa2x5Jw1T8+sABN0kFdLvwm0lFSP+uqgDZmq3SVcCJ 6EojIry0utvsg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Wed, 30 Aug 2023 19:35:32 +0200 Message-Id: <85bcd0af56521209f40e76e0cac626c4f02b7df5.1693416477.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: Subject: [PATCH v2 5/7] regulator/core: regulator_lock_contended: wrap ww_mutex lock sequence restart MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= To: Liam Girdwood , Mark Brown Cc: Douglas Anderson , linux-kernel@vger.kernel.org, Stephen Boyd Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wrap locking a regulator after a failed ww_mutex locking sequence with a new function. This is to deduplicate occurrences of the pattern and make it self-documenting. Signed-off-by: Micha=C5=82 Miros=C5=82aw Reviewed-by: Douglas Anderson --- drivers/regulator/core.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e89c12d27a9d..7201927c5d5b 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -154,6 +154,22 @@ static inline int regulator_lock_nested(struct regulat= or_dev *rdev, return 0; } =20 +/** + * regulator_lock_contended - retry locking a regulator + * @rdev: regulator source + * @ww_ctx: w/w mutex acquire context + * + * Locks a regulator after a failed locking sequence (aborted + * with -EDEADLK). + */ +static inline void regulator_lock_contended(struct regulator_dev *rdev, + struct ww_acquire_ctx *ww_ctx) +{ + ww_mutex_lock_slow(&rdev->mutex, ww_ctx); + rdev->ref_cnt++; + rdev->mutex_owner =3D current; +} + /** * regulator_lock - lock a single regulator * @rdev: regulator source @@ -218,9 +234,7 @@ static void regulator_lock_two(struct regulator_dev *rd= ev1, while (true) { regulator_unlock(held); =20 - ww_mutex_lock_slow(&contended->mutex, ww_ctx); - contended->ref_cnt++; - contended->mutex_owner =3D current; + regulator_lock_contended(contended, ww_ctx); swap(held, contended); ret =3D regulator_lock_nested(contended, ww_ctx); =20 @@ -376,10 +390,8 @@ static void regulator_lock_dependent(struct regulator_= dev *rdev, =20 do { if (new_contended_rdev) { - ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx); + regulator_lock_contended(new_contended_rdev, ww_ctx); old_contended_rdev =3D new_contended_rdev; - old_contended_rdev->ref_cnt++; - old_contended_rdev->mutex_owner =3D current; } =20 err =3D regulator_lock_recursive(rdev, @@ -6085,10 +6097,8 @@ static void regulator_summary_lock(struct ww_acquire= _ctx *ww_ctx) =20 do { if (new_contended_rdev) { - ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx); + regulator_lock_contended(new_contended_rdev, ww_ctx); old_contended_rdev =3D new_contended_rdev; - old_contended_rdev->ref_cnt++; - old_contended_rdev->mutex_owner =3D current; } =20 err =3D regulator_summary_lock_all(ww_ctx, --=20 2.39.2