Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2163112iof; Tue, 7 Jun 2022 21:51:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+LkstH8ZYey7lodocCMdXLWRN1NL2BZbwinC4l+f6eF5Ez5TnmiweLLV2TgkvKKFZszFq X-Received: by 2002:a17:902:ce11:b0:167:7d4a:964b with SMTP id k17-20020a170902ce1100b001677d4a964bmr13557276plg.37.1654663892081; Tue, 07 Jun 2022 21:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654663892; cv=none; d=google.com; s=arc-20160816; b=x+WN09oQDEeybquFO89eqdNROixVN6I4rCnU52mekOLcjteAxlHhG5lCaV3F4Jkgy6 uglXFGOo7k7Gy2Q+Oc/FK/dc4tHZf4rlo241bnZa9tZPA2zHp3IWs3DEUvF6ArGCaRBT rlblv2YtPEbQ/An5OkSVTOCX0NDwtlxPFc2z49KzmwRTHQKjXFv4YsY0KAUBbXOyUg01 +NlWhY8tu6czWFCVH7R8xlF3gzjdLTfw2ojJFUIZKgQ8VoE/9i5vYjdl641je5x6XZYn WEB+0S8e7FbFuE4Dp/4zE9KzZNRZxwDTZz++r8/Ehcz0OM3W2KFY+Ch9Fh3RN6lsF2yW URmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qPBg3BS8hsYUH6R/LKAj+HR5m46ThpfupBwHjlmm9E4=; b=Yr9l0j17YOOL5aDccopsCpUtQmIVRXEYRoNRid+MqZBdLNTf5+j0tmp5ZKR8VoVPrE 1F8X+QJuU44G4zBiI8PXHnIBgVna0zZffMTJL2SfK5fZNQPHlFqXJ4AWn4CyqhwJUN+K UEjbn7v7xah0luuPSQ76b8eur/F1k2IdySjS8iyzhloxiBPYBln6yEntW52KpD+ju5AR FTP+J1E29fYPYJc00aNCCbexiXenV6POukYzUEulccjIG6MN9eAs3C8r6+uT5Z7c9zO1 j2HAopg9PL9Jt4+cAmRCDLGNIJ9bjnMeb0V9J9etrp0H7zhE5fzlYoLCLutZahGeSUnO 0MdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rBe/bxuL"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x82-20020a633155000000b003995a4f48c4si26717187pgx.377.2022.06.07.21.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:51:32 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rBe/bxuL"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A04653119A2; Tue, 7 Jun 2022 21:21:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381521AbiFGWmy (ORCPT + 99 others); Tue, 7 Jun 2022 18:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380857AbiFGVbZ (ORCPT ); Tue, 7 Jun 2022 17:31:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C1B322BAE9; Tue, 7 Jun 2022 12:03:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 265756159D; Tue, 7 Jun 2022 19:03:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AA9DC385A5; Tue, 7 Jun 2022 19:03:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628611; bh=ccEUHQQy2f2V9AzPwFK1n2OW3NKEul9X0Jjqw9iaasc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rBe/bxuLKvu1TFLkSQzFUoN9ub1Rb4iSzOfoi1fRuGIe724lBcoJFumTw1Xb7PEOU 4QKoo84HSNCW346V3/Xl7rtJudCGVnzfqAmruzFWuGyFQ3NX6GGFsDMUhnIeaWoRua wVO73FladzqKLdPhm8p+smofQyDh8CtgJy7m3Qzs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zev Weiss , Mark Brown , Sasha Levin Subject: [PATCH 5.18 392/879] regulator: core: Fix enable_count imbalance with EXCLUSIVE_GET Date: Tue, 7 Jun 2022 18:58:30 +0200 Message-Id: <20220607165014.243054831@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Zev Weiss [ Upstream commit c3e3ca05dae37f8f74bb80358efd540911cbc2c8 ] Since the introduction of regulator->enable_count, a driver that did an exclusive get on an already-enabled regulator would end up with enable_count initialized to 0 but rdev->use_count initialized to 1. With that starting point the regulator is effectively stuck enabled, because if the driver attempted to disable it it would fail the enable_count underflow check in _regulator_handle_consumer_disable(). The EXCLUSIVE_GET path in _regulator_get() now initializes enable_count along with rdev->use_count so that the regulator can be disabled without underflowing the former. Signed-off-by: Zev Weiss Fixes: 5451781dadf85 ("regulator: core: Only count load for enabled consumers") Link: https://lore.kernel.org/r/20220505043152.12933-1-zev@bewilderbeest.net Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d2553970a67b..c4d844ffad7a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2133,10 +2133,13 @@ struct regulator *_regulator_get(struct device *dev, const char *id, rdev->exclusive = 1; ret = _regulator_is_enabled(rdev); - if (ret > 0) + if (ret > 0) { rdev->use_count = 1; - else + regulator->enable_count = 1; + } else { rdev->use_count = 0; + regulator->enable_count = 0; + } } link = device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); -- 2.35.1