Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1142030rdb; Sun, 20 Aug 2023 20:09:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnH9zCh7qrSKzdh3MN3Ti6fir5OBbMrh+gUtW8Lq/x4q//JQGYk25+sVgWQ4oWvx/i/VNA X-Received: by 2002:aa7:d9cd:0:b0:523:4025:49f0 with SMTP id v13-20020aa7d9cd000000b00523402549f0mr3518582eds.26.1692587374287; Sun, 20 Aug 2023 20:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692587374; cv=none; d=google.com; s=arc-20160816; b=hezsskftPxLOCEzrp6qo6Gs7pEDZfMZ0TMm2xJYaKW9aT207p6yNAjt/ENEdFlXZ5n hEqCpTdV7Dw0wnxfYQhBrA07rgcjyqDCNRCTwczkjImLmx8jDH6CzTQCz8DvogN3OeIR fu/b9hCPU3FaRI7q270RLFMc5Ucm2n4jl8nCr2Nd247LKkR/Lwt145T243ZB9rk+mUyy 9zWbO4BsyLzvNUQamFLuqatbeZF9grMCaUe/KNcpbk59c2ZvecGhwPdvLyeoMnct5fMN +WckohPNPj/njixxNQml1JlesK+aC+FgbiFxONzhJOsmy+p7e0ODy8y/41zNzKTDFh7F 38Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:content-transfer-encoding :mime-version:subject:references:in-reply-to:message-id:date :dkim-signature; bh=ldL2TqPRCOZFptcshLnfjo+QnrDw2C4Zv6ZJ+mjSm3A=; fh=uJWnp8dzYVQueeC5eaum++/inO86C8Gk7Ei1dGbAuxk=; b=bVj9sfs4DeDzzWrSomhFma66Q/MWx+404reVg1zNnvg/dp79NCoPJpu0+1KOIjI4s5 pjVZK1bAyxx89v5UvWv52CQNMYFR97b2zNQDHVn+8X1k/6IzaJ4nJBI2uLucOH4R7btd Ykx9DGrjTCsdEpkHSo3BR986z0wNDPRoCd9yLoKgRVGOiR9jSrcXKN6FcM6/PiANPaj6 c0Am79q7NUYJAxSFFvWb233xI1MoMdIYpnl+6rUl11Eid7MwEnYQYCjtJDRA1CwhXhAs XE8/Ll+bAlRjaQM9XKZee4rHVk0+PuqfY5lbLMez2JjwqVxGRB9CjUeKI4JoMqHgQ/Fs 2A9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=cyBrcl6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a056402069300b00525774c622asi4824425edy.347.2023.08.20.20.09.03; Sun, 20 Aug 2023 20:09:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=cyBrcl6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbjHTAKl (ORCPT + 99 others); Sat, 19 Aug 2023 20:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjHTAKW (ORCPT ); Sat, 19 Aug 2023 20:10:22 -0400 Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F21EBA2C13 for ; Sat, 19 Aug 2023 13:15:44 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RSqk73tQQzDP; Sat, 19 Aug 2023 22:15:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1692476143; bh=YtPxaSJGaYviQtheKr8WW3ztuiAMjl4/E99vF4LFKWg=; h=Date:In-Reply-To:References:Subject:From:To:Cc:From; b=cyBrcl6tONyHMHe4XVqxrsMla0/aQQ7tc1uDzhc8/EPOstcGM0VJaCOvSRnaV1Ktu 3TmHfHXP6HFh+p39fbRtP1Baptw/KvHlwujqcYgG2132t494+TCfErLfAPdR9DPaH+ 2MadHHAFouLtqyJmVg7saOMpmob9IUHKOo/6n1ilNTpN7Ysk3r/2dO7PEeBgq5C7tO dT/0M/4GouIryBXgWhf1OXVwFC0l6tKBZo8JEu4Z6lKAQ+JGg7MeYe1HHx+HAeDU1f aP7+ShOw+iksWiJR4pwHLl2DB69sSxYjifAmaanEukiZkkVdNdP2Rq5uWHaEFccvLg BEskEBNT6m9Ig== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Sat, 19 Aug 2023 22:15:43 +0200 Message-Id: <89a905854995cf662a122792d8d0c781e39ea7da.1692475736.git.mirq-linux@rere.qmqm.pl> In-Reply-To: <0e37d1f09718a6ab9204b367ff528ab02df25ac7.1692475736.git.mirq-linux@rere.qmqm.pl> References: <0e37d1f09718a6ab9204b367ff528ab02df25ac7.1692475736.git.mirq-linux@rere.qmqm.pl> Subject: [PATCH 2/2] regulator: core: skip nesting lock for -EDEADLK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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ł Mirosław --- 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 regulator_dev *rdev, mutex_lock(®ulator_nesting_mutex); - if (!ww_mutex_trylock(&rdev->mutex, ww_ctx)) { - if (rdev->mutex_owner != current) { - mutex_unlock(®ulator_nesting_mutex); - ret = ww_mutex_lock(&rdev->mutex, ww_ctx); - mutex_lock(®ulator_nesting_mutex); - } + if (!ww_mutex_trylock(&rdev->mutex, ww_ctx) && + rdev->mutex_owner != current) { + mutex_unlock(®ulator_nesting_mutex); + ret = ww_mutex_lock(&rdev->mutex, ww_ctx); + if (ret == -EDEADLK) + return ret; + mutex_lock(®ulator_nesting_mutex); } - if (ret != -EDEADLK) { - rdev->ref_cnt++; - rdev->mutex_owner = current; - } + rdev->ref_cnt++; + rdev->mutex_owner = current; mutex_unlock(®ulator_nesting_mutex); -- 2.39.2