From nobody Wed Dec 17 16:12:17 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 DF209EE49A3 for ; Sun, 20 Aug 2023 00:27:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229521AbjHTA1G (ORCPT ); Sat, 19 Aug 2023 20:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbjHTA0p (ORCPT ); Sat, 19 Aug 2023 20:26:45 -0400 Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FACFD36EB for ; Sat, 19 Aug 2023 15:46:10 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RSv3h4ZzdzDP; Sun, 20 Aug 2023 00:46:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1692485168; bh=cb3x8n2KvdEKrO5gnhlOylDSeakeIsSLrBnHc0wj/Xs=; h=Date:In-Reply-To:References:Subject:From:To:Cc:From; b=SYEFXf2h02SBxxE/mu1xLvA0/X+feaAQqA7UBg0b1om6HixQ+Bwivq7akoud2dkGI qktu0Mr5N6nTey+zjTCm6N2fNH8z0qK/IVMAtTkHKvakHzD52KLolR3hr6XW0Rljqm TUvHA05opmt5e6jUsz1Hv+s55XtMhHzrf4GjSPoKFEA//CMf/HRclC5C32fWrJBwjW GRouYo2Soh8S3qqNwI+tze89jR7cd0yxa3fYnDKxmERWjld5/dTrkm8B3aF8orhEFA oFurvUib4DM2JTwDEVcyA1UJkHgf8Z/Dh8V8/2S5g6riMxL963Y/25cfMYw01q5uU1 ez+eCjDRQD4Ew== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Sun, 20 Aug 2023 00:46:08 +0200 Message-Id: <0e37d1f09718a6ab9204b367ff528ab02df25ac7.1692484240.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: Subject: [PATCH 1/6] regulator: core: simplify regulator_lock_nested() 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: linux-kernel@vger.kernel.org, Dmitry Osipenko , Douglas Anderson Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org `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=C5=82 Miros=C5=82aw Reviewed-by: Douglas Anderson --- 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_d= ev *rdev, int ops) static inline int regulator_lock_nested(struct regulator_dev *rdev, struct ww_acquire_ctx *ww_ctx) { - bool lock =3D false; int ret =3D 0; =20 mutex_lock(®ulator_nesting_mutex); =20 if (!ww_mutex_trylock(&rdev->mutex, ww_ctx)) { - if (rdev->mutex_owner =3D=3D current) - rdev->ref_cnt++; - else - lock =3D true; - - if (lock) { + if (rdev->mutex_owner !=3D current) { mutex_unlock(®ulator_nesting_mutex); ret =3D ww_mutex_lock(&rdev->mutex, ww_ctx); mutex_lock(®ulator_nesting_mutex); } - } else { - lock =3D true; } =20 - if (lock && ret !=3D -EDEADLK) { + if (ret !=3D -EDEADLK) { rdev->ref_cnt++; rdev->mutex_owner =3D current; } --=20 2.39.2