From nobody Thu Dec 18 20:37:42 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 14A2DC83F17 for ; Wed, 30 Aug 2023 18:34:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234728AbjH3Seo (ORCPT ); Wed, 30 Aug 2023 14:34:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343955AbjH3Rfh (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 546A0193 for ; Wed, 30 Aug 2023 10:35:35 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RbWfF3GB8zjJ; 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=dWJXSE23EEsNF2ABidxY7QtS4t5FWf+OeZGytVGqGR8=; h=Date:In-Reply-To:References:Subject:From:To:Cc:From; b=l9cjpoKiexV48zwpCG2Zkfb3Ds0UQvudFGggvDKy4nEvJnJMQBvenJi1vwuBxS96N D5461n2lcq8l1JOa/IgGertHluRUaVh+mGso9Ievi3EtvlmMhDZUjeChOY0GVM4Dmr dWqAsta0V4sMW0uMJ1nnCnS7Puj9T1yUlXDVGeLdFuAp0sz8nOb2xakrra6toLK6hz POEtdbL8/Yxby/kDtDdSGg2anisNlvqDEKuoUu6sfg1ci5VEo/LSssrsMF/1SprnhS AJbxVGrvqK81qANtOK9bP/CvEE6XwUJ7ydC2IYslNIl1cZyG6BCXn0LtzJW5JDAk0P pHeuKbujphmfA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Wed, 30 Aug 2023 19:35:33 +0200 Message-Id: <3240d792149f32fb4164ad7042091daf9f59f9a3.1693416477.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: Subject: [PATCH v2 6/7] regulator/core: regulator_lock_two: propagate error up 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 Fix up error paths from regulator_lock_two(): although it should not fail, returning with half-locked state after issuing a WARN() asks for even more trouble. Fixes: cba6cfdc7c3f ("regulator: core: Avoid lockdep reports when resolving= supplies") Signed-off-by: Micha=C5=82 Miros=C5=82aw --- v2: - updated kerneldoc - call ww_acquire_done() on all exits --- 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 7201927c5d5b..3f9621621da9 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -209,11 +209,12 @@ static void regulator_unlock(struct regulator_dev *rd= ev) * @rdev2: second regulator * @ww_ctx: w/w mutex acquire context * - * Locks both rdevs using the regulator_ww_class. + * Locks both rdevs using the regulator_ww_class. Returns error if an + * unexpected error has been detected during a locking sequence. */ -static void regulator_lock_two(struct regulator_dev *rdev1, - struct regulator_dev *rdev2, - struct ww_acquire_ctx *ww_ctx) +static int regulator_lock_two(struct regulator_dev *rdev1, + struct regulator_dev *rdev2, + struct ww_acquire_ctx *ww_ctx) { struct regulator_dev *held, *contended; int ret; @@ -222,10 +223,13 @@ static void regulator_lock_two(struct regulator_dev *= rdev1, =20 /* Try to just grab both of them */ ret =3D regulator_lock_nested(rdev1, ww_ctx); - WARN_ON(ret); + if (WARN_ON(ret)) + goto exit; ret =3D regulator_lock_nested(rdev2, ww_ctx); - if (ret !=3D -EDEADLOCK) { - WARN_ON(ret); + if (!ret) + goto exit; + if (WARN_ON(ret !=3D -EDEADLOCK)) { + regulator_unlock(rdev1); goto exit; } =20 @@ -239,13 +243,15 @@ static void regulator_lock_two(struct regulator_dev *= rdev1, ret =3D regulator_lock_nested(contended, ww_ctx); =20 if (ret !=3D -EDEADLOCK) { - WARN_ON(ret); + if (WARN_ON(ret)) + regulator_unlock(held); break; } } =20 exit: ww_acquire_done(ww_ctx); + return ret; } =20 /** @@ -2113,7 +2119,11 @@ static int regulator_resolve_supply(struct regulator= _dev *rdev) * between rdev->supply null check and setting rdev->supply in * set_supply() from concurrent tasks. */ - regulator_lock_two(rdev, r, &ww_ctx); + ret =3D regulator_lock_two(rdev, r, &ww_ctx); + if (ret < 0) { + put_device(&r->dev); + return ret; + } =20 /* Supply just resolved by a concurrent task? */ if (rdev->supply) { --=20 2.39.2