From: Liang He <windhl@126.com>
To: jejb@linux.ibm.com, martin.petersen@oracle.com,
bvanassche@acm.org, windhl@126.com, linux-scsi@vger.kernel.org
Subject: [PATCH v2] ufs: host: ufschd-pltfrm: Hold reference returned by of_parse_phandle()
Date: Fri, 15 Jul 2022 08:17:03 +0800 [thread overview]
Message-ID: <20220715001703.389981-1-windhl@126.com> (raw)
In ufshcd_populate_vreg(), we should hold the reference returned by
of_parse_phandle() and then use it to call of_node_put() for refcount
balance.
Fixes: aa4976130934 ("ufs: Add regulator enable support")
Signed-off-by: Liang He <windhl@126.com>
---
changelog:
v2: use a proper helper name advised by Bart Van Assche.
v1: add a helper to fix the bug
v1 link: https://lore.kernel.org/all/20220714055413.373449-1-windhl@126.com/
drivers/ufs/host/ufshcd-pltfrm.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/ufs/host/ufshcd-pltfrm.c b/drivers/ufs/host/ufshcd-pltfrm.c
index e7332cc65b1f..46ded7813c42 100644
--- a/drivers/ufs/host/ufshcd-pltfrm.c
+++ b/drivers/ufs/host/ufshcd-pltfrm.c
@@ -108,6 +108,21 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
return ret;
}
+static bool phandle_exists(const struct device_node *np,
+ const char *phandle_name,
+ int index)
+{
+ struct device_node *parse_np = of_parse_phandle(np, phandle_name, index);
+ bool ret = false;
+
+ if (parse_np) {
+ ret = true;
+ of_node_put(parse_np);
+ }
+
+ return ret;
+}
+
#define MAX_PROP_SIZE 32
static int ufshcd_populate_vreg(struct device *dev, const char *name,
struct ufs_vreg **out_vreg)
@@ -122,7 +137,7 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
}
snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", name);
- if (!of_parse_phandle(np, prop_name, 0)) {
+ if (!phandle_exists(np, prop_name, 0)) {
dev_info(dev, "%s: Unable to find %s regulator, assuming enabled\n",
__func__, prop_name);
goto out;
--
2.25.1
next reply other threads:[~2022-07-15 0:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 0:17 Liang He [this message]
2022-07-16 13:50 ` [PATCH v2] ufs: host: ufschd-pltfrm: Hold reference returned by of_parse_phandle() Bart Van Assche
2022-07-17 3:03 ` Liang He
2022-07-17 14:58 ` Bart Van Assche
2022-07-18 8:30 ` Liang He
2022-07-19 2:46 ` Liang He
2022-07-19 18:12 ` Bart Van Assche
2022-07-20 0:48 ` Liang He
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=20220715001703.389981-1-windhl@126.com \
--to=windhl@126.com \
--cc=bvanassche@acm.org \
--cc=jejb@linux.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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