diff mbox series

[v3] ufs: host: ufshcd-pltfrm: Hold reference returned by of_parse_phandle()

Message ID 20220719071529.1081166-1-windhl@126.com
State New
Headers show
Series [v3] ufs: host: ufshcd-pltfrm: Hold reference returned by of_parse_phandle() | expand

Commit Message

Liang He July 19, 2022, 7:15 a.m. UTC
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:

 v3: fix indentation problem and use 'ret parse_np != NULL'
 v2: change helper name
 v1: fix holding bug

 Here we also change the indentation of original 'ufshcd_populate_vreg()'

 drivers/ufs/host/ufshcd-pltfrm.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Martin K. Petersen July 27, 2022, 3:15 a.m. UTC | #1
On Tue, 19 Jul 2022 15:15:29 +0800, Liang He wrote:

> 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.
> 
> 

Applied to 5.19/scsi-fixes, thanks!

[1/1] ufs: host: ufshcd-pltfrm: Hold reference returned by of_parse_phandle()
      https://git.kernel.org/mkp/scsi/c/a3435afba87d
diff mbox series

Patch

diff --git a/drivers/ufs/host/ufshcd-pltfrm.c b/drivers/ufs/host/ufshcd-pltfrm.c
index e7332cc65b1f..173aea8e9997 100644
--- a/drivers/ufs/host/ufshcd-pltfrm.c
+++ b/drivers/ufs/host/ufshcd-pltfrm.c
@@ -108,9 +108,20 @@  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);
+
+	if (parse_np)
+		of_node_put(parse_np);
+
+	return parse_np != NULL;
+}
+
 #define MAX_PROP_SIZE 32
 static int ufshcd_populate_vreg(struct device *dev, const char *name,
-		struct ufs_vreg **out_vreg)
+				struct ufs_vreg **out_vreg)
 {
 	char prop_name[MAX_PROP_SIZE];
 	struct ufs_vreg *vreg = NULL;
@@ -122,7 +133,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;