All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <lgirdwood@gmail.com>, <broonie@kernel.org>,
	<javier@osg.samsung.com>, <mirq-linux@rere.qmqm.pl>,
	<christian@kohlschutter.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/2] regulator: core: fix module refcount leak in set_supply()
Date: Thu, 1 Dec 2022 20:27:05 +0800	[thread overview]
Message-ID: <20221201122706.4055992-2-yangyingliang@huawei.com> (raw)
In-Reply-To: <20221201122706.4055992-1-yangyingliang@huawei.com>

If create_regulator() fails in set_supply(), the module refcount
needs be put to keep refcount balanced.

Fixes: e2c09ae7a74d ("regulator: core: Increase refcount for regulator supply's module")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/regulator/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index bc4bba899aea..4a7d8ec415e8 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1638,10 +1638,11 @@ static int set_supply(struct regulator_dev *rdev,
 	if (!try_module_get(supply_rdev->owner))
 		return -ENODEV;
 
 	rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY");
 	if (rdev->supply == NULL) {
+		module_put(supply_rdev->owner);
 		err = -ENOMEM;
 		return err;
 	}
 	supply_rdev->open_count++;
 
-- 
2.25.1


  reply	other threads:[~2022-12-01 12:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 12:27 [PATCH 0/2] regulator: core: fix some resource leaks Yang Yingliang
2022-12-01 12:27 ` Yang Yingliang [this message]
2022-12-01 12:27 ` [PATCH 2/2] regulator: core: fix resource leak in regulator_register() Yang Yingliang
2022-12-01 17:19   ` Mark Brown
2022-12-01 18:16 ` [PATCH 0/2] regulator: core: fix some resource leaks 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=20221201122706.4055992-2-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=broonie@kernel.org \
    --cc=christian@kohlschutter.com \
    --cc=javier@osg.samsung.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mirq-linux@rere.qmqm.pl \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.