linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rui Zhang <zr.zhang@vivo.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org
Cc: kernel@vivo.com, Rui Zhang <zr.zhang@vivo.com>
Subject: [PATCH] regulator: core: fix use_count leakage when handling boot-on
Date: Tue, 22 Nov 2022 18:32:51 +0800	[thread overview]
Message-ID: <20221122103251.13064-1-zr.zhang@vivo.com> (raw)

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 <zr.zhang@vivo.com>
---
 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 e8c00a884f1f..1cfac32121c0 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1596,7 +1596,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.34.1

________________________________

本邮件及其附件内容可能含有机密和/或隐私信息,仅供指定个人或机构使用。若您非发件人指定收件人或其代理人,请勿使用、传播、复制或存储此邮件之任何内容或其附件。如您误收本邮件,请即以回复或电话方式通知发件人,并将原始邮件、附件及其所有复本删除。谢谢。
The contents of this message and any attachments may contain confidential and/or privileged information and are intended exclusively for the addressee(s). If you are not the intended recipient of this message or their agent, please note that any use, dissemination, copying, or storage of this message or its attachments is not allowed. If you receive this message in error, please notify the sender by reply the message or phone and delete this message, any attachments and any copies immediately.
Thank you

             reply	other threads:[~2022-11-22 10:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 10:32 Rui Zhang [this message]
2022-11-29 17:50 ` [PATCH] regulator: core: fix use_count leakage when handling boot-on Mark Brown
2022-12-01 13:24 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221122103251.13064-1-zr.zhang@vivo.com \
    --to=zr.zhang@vivo.com \
    --cc=broonie@kernel.org \
    --cc=kernel@vivo.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).