From nobody Wed Dec 17 16:12:48 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 35616EE49AC for ; Sun, 20 Aug 2023 00:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229665AbjHTA1J (ORCPT ); Sat, 19 Aug 2023 20:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjHTA0p (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 D0717D36EC 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 4RSv3j0W9gzDk; Sun, 20 Aug 2023 00:46:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1692485169; bh=YtPxaSJGaYviQtheKr8WW3ztuiAMjl4/E99vF4LFKWg=; h=Date:In-Reply-To:References:Subject:From:To:Cc:From; b=ku31gmGanlGog1ZjXQr6SYu9WueRRIsD1NzauqoHufTQis/qn0JCdfzWR0i8Wp7XJ YHSgQRVFxG5YDZ+FCVAnNNnD3PXZdDecbW6HGDQNsxiORsetDxofS4Otev89qj/HQs qErD0TXfmzIzYZzhhwirsudamppTph6iw6GgM+0jAn31xValLy1zXzun6yL1cgWLJL 7jeDHKzs5AAZuREBHk+eka4f1QiBazD2ARb392gltkiERVFaFradTnFL/hKDEIVdgY Z3cgdhtu1MOKrYxrCASn30GqgSK2GnEjJylCx5xm26R+4asx1HNzLMkkW3i/GVj0Uc KBUCWB2p1bdWQ== 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: <89a905854995cf662a122792d8d0c781e39ea7da.1692484240.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: Subject: [PATCH 2/6] regulator: core: skip nesting 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: linux-kernel@vger.kernel.org, Dmitry Osipenko , Douglas Anderson 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. Signed-off-by: Micha=C5=82 Miros=C5=82aw Reviewed-by: Douglas Anderson --- 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