Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1524370rwj; Sun, 18 Dec 2022 09:51:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gYJl6r1I0et81TpWRelq//L+oYLEyGc4QtZ+zUsYT9xSCpi6WU2Jwie7OEpA0pOr/poC+ X-Received: by 2002:a17:902:c141:b0:189:6e2b:b742 with SMTP id 1-20020a170902c14100b001896e2bb742mr40669690plj.43.1671385861740; Sun, 18 Dec 2022 09:51:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671385861; cv=none; d=google.com; s=arc-20160816; b=kPGvTRPW+osL7QxRybPvDLV8TnwawO8KRiP+Wr4L8KiBOzZhPqrlDKBlPZCbpFPrNY vzijPnatyOVqXM5b6tNkKNbIs94/EfLM2bsrDXWdj99mdhNxtINLmPeS1O+G7L/JCJJI w2RLWrXIWOis6EoJRzvU4W/noZjay8iJAV1rJJtcPFvtOUh1+cMMITn5HEYEJkuVlgMy 4ZPmOKhxxBNmed9/L3kCQy+6zZc26BNRRMeXmAPv9FqlhpvanQr7nColr4m3TTKV0svo tbfAEkf+ePAue6EfaPYhCFSbw0f25rIqHR5fnGtwbv6wjcbMMaEPi1ruvSvUR5HQ6ka2 g+Iw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9sZH85YHOMQuSTc8VCms87OkTaEk6caisw5iFyKJGdU=; b=qYv2SwKJcsSQoIr+Lk8SK5Px5Nig1wk+bp3ycKznjjeqhX/seQsyhBzDOkFtOl3dtp +gawjXP+rcz9UgIOabFLA6UgR/jwlGz+6cgQkqSxw4qQu7Kn7w9uvgzI392gF6OlpBzm j31g5HgYq6hz/B4fjBiMzjeCX45vzOS6QcIYQK3XcVNo2wyWTiS5x5opvNy8anMRKoZS q4iXuSZekL283NNvhTUYE9eobbPkbnFMW8PPkxZW4UIeCN4EAsU7L2xxqC2t/+h0yUTC VZLxr6LV8Pv9/Eru6nxJWA+fY/UXCB7gLTEYN5LOywP0eDaLb6l1rtCcVChQKVjE0/Pn B6dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uf1pIAnm; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a170902e54a00b001898d8881d1si8711539plf.598.2022.12.18.09.50.49; Sun, 18 Dec 2022 09:51:01 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=Uf1pIAnm; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231537AbiLRQpC (ORCPT + 70 others); Sun, 18 Dec 2022 11:45:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232437AbiLRQoW (ORCPT ); Sun, 18 Dec 2022 11:44:22 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3617CC16; Sun, 18 Dec 2022 08:15:43 -0800 (PST) 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 71A7460C99; Sun, 18 Dec 2022 16:15:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29BCDC433F0; Sun, 18 Dec 2022 16:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380142; bh=hruMlHNLXmBwMxIYmTb9Gv7YQfxrO7SUpelH+78KGQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uf1pIAnmdTBQaG7Lya+IqYzre5UpYcOdJE40aq8FayjFdFbO7LHK+2cD8vmMqQz6o r768CMo95E6nNwyUXPEh0v3iZ+g0c3i5wPxzhSram27v5c1TopNY5xeHlDFuXXcXGR Sny9DK1iVJYsdGU3Y2ANz+Pm6n5azc87eOq4jNl3sDzMkcaP1sdkVQqRDFM+oCnQQc H+4WJmmwbN9MNT8JG8PWIwiD2Rm7PIarl2tvBAvw4htnYawJ2nsahmEmN9PWW9GxKY 50JIFxsfpXl8PtoSOP094ead6wFu8ZXMspskHBea5Jjx5KrNe6V0Ys6IVf2KnkAtJl fFTMpwKxbeT7Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rui Zhang , Mark Brown , Sasha Levin , lgirdwood@gmail.com Subject: [PATCH AUTOSEL 5.15 40/46] regulator: core: fix use_count leakage when handling boot-on Date: Sun, 18 Dec 2022 11:12:38 -0500 Message-Id: <20221218161244.930785-40-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Rui Zhang [ Upstream commit 0591b14ce0398125439c759f889647369aa616a0 ] I found a use_count leakage towards supply regulator of rdev with boot-on option. ┌───────────────────┐ ┌───────────────────┐ │ regulator_dev A │ │ regulator_dev B │ │ (boot-on) │ │ (boot-on) │ │ use_count=0 │◀──supply──│ use_count=1 │ │ │ │ │ └───────────────────┘ └───────────────────┘ In case of rdev(A) configured with `regulator-boot-on', the use_count of supplying regulator(B) will increment inside regulator_enable(rdev->supply). Thus, B will acts like always-on, and further balanced regulator_enable/disable cannot actually disable it anymore. However, B was also configured with `regulator-boot-on', we wish it could be disabled afterwards. Signed-off-by: Rui Zhang Link: https://lore.kernel.org/r/20221201033806.2567812-1-zr.zhang@vivo.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 221ae807b379..18ffa787d0a2 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1531,7 +1531,13 @@ static int set_machine_constraints(struct regulator_dev *rdev) if (rdev->supply_name && !rdev->supply) return -EPROBE_DEFER; - if (rdev->supply) { + /* If supplying regulator has already been enabled, + * it's not intended to have use_count increment + * when rdev is only boot-on. + */ + if (rdev->supply && + (rdev->constraints->always_on || + !regulator_is_enabled(rdev->supply))) { ret = regulator_enable(rdev->supply); if (ret < 0) { _regulator_put(rdev->supply); -- 2.35.1