public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ufs: host: ufschd-pltfrm: Hold reference returned by  of_parse_phandle()
@ 2022-07-15  0:17 Liang He
  2022-07-16 13:50 ` Bart Van Assche
  0 siblings, 1 reply; 8+ messages in thread
From: Liang He @ 2022-07-15  0:17 UTC (permalink / raw)
  To: jejb, martin.petersen, bvanassche, windhl, linux-scsi

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-20  0:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-15  0:17 [PATCH v2] ufs: host: ufschd-pltfrm: Hold reference returned by of_parse_phandle() Liang He
2022-07-16 13:50 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox