From nobody Fri Dec 19 04:03:21 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 1B2F8C83F19 for ; Wed, 30 Aug 2023 18:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238850AbjH3SjS (ORCPT ); Wed, 30 Aug 2023 14:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343951AbjH3Rfg (ORCPT ); Wed, 30 Aug 2023 13:35:36 -0400 Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CE4C193 for ; Wed, 30 Aug 2023 10:35:33 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RbWfC4LTSzTw; Wed, 30 Aug 2023 19:35:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1693416931; bh=hSMQQTeSudZxbDfDsrdeeJ4mA/Mwq7wjXr2m2bQXnP8=; h=Date:In-Reply-To:References:Subject:From:To:Cc:From; b=O6r6i1v+gf7ZVgP9xLvTqNPD7Wia6WA7XFHqAgNdFq+Z1JsmxbUhtMPF1vW+2q9nc 3X8f5nrCq9PdEwADcLxP9kWVFpIcWylHLaQjgfzdug9lh2caDSF3MRuMDUIbK3z3kC dc15kKk1X/01vauF78ELCaixZFfYrsw14i9fJTGYgT5QEZVU77w0mZIiOZWLFE0Tg/ 0qwPjEzS2GDsrNA1FTwJoxI4ZbkGj/1Xs8e4RUqSRjrDNWekA5o96Vr0RFx+eg0HQl nVH0rSQ9qvG+/3/qBqE0gxmt3UHpzXc8KkaRRe1ZpmlUlyW7jq8r7EuqieYB//iSF6 VVoXRLaIril+A== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Wed, 30 Aug 2023 19:35:31 +0200 Message-Id: In-Reply-To: References: Subject: [PATCH v2 2/7] regulator/core: regulator_lock_nested: skip extra lock for -EDEADLK 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 When ww_mutex_lock() returns -EDEADLK the nesting mutex-protected section becomes a no-op. Return early and avoid the extra lock. Reviewed-by: Douglas Anderson Signed-off-by: Micha=C5=82 Miros=C5=82aw --- drivers/regulator/core.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 215b721e5cd4..921c7039baa3 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -145,18 +145,17 @@ static inline int regulator_lock_nested(struct regula= tor_dev *rdev, =20 mutex_lock(®ulator_nesting_mutex); =20 - if (!ww_mutex_trylock(&rdev->mutex, ww_ctx)) { - 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); - } + if (!ww_mutex_trylock(&rdev->mutex, ww_ctx) && + rdev->mutex_owner !=3D current) { + mutex_unlock(®ulator_nesting_mutex); + ret =3D ww_mutex_lock(&rdev->mutex, ww_ctx); + if (ret =3D=3D -EDEADLK) + return ret; + mutex_lock(®ulator_nesting_mutex); } =20 - if (ret !=3D -EDEADLK) { - rdev->ref_cnt++; - rdev->mutex_owner =3D current; - } + rdev->ref_cnt++; + rdev->mutex_owner =3D current; =20 mutex_unlock(®ulator_nesting_mutex); =20 --=20 2.39.2