Skip to contentSkip to conversation

ufs: host: ufschd-pltfrm: Hold reference returned by of_parse_phandle()

PATCH Superseded Liang He 2 participants 3 messages Jul 14, 2022 SCSI

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 ufs: host: ufschd-pltfrm: Hold reference returned by of_parse_phandle()

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")

---

We add a helper to check the return value of_parse_phandle() as we
do not need the reference, otherwise we need to declare a device_node in ufshcd_populate_vreg().

 drivers/ufs/host/ufshcd-pltfrm.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/ufs/host/ufshcd-pltfrm.c +16 -1
index e7332cc65b1f..2cb409d9ed3d 100644
@@ -108,6 +108,21 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
 	return ret;
 }
 
+static bool is_of_parse_phandle(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 (!is_of_parse_phandle(np, prop_name, 0)) {
 		dev_info(dev, "%s: Unable to find %s regulator, assuming enabled\n",
 				__func__, prop_name);
 		goto out;
Signature · 1 line
2.25.1
#1 lore raw

drivers/ufs/host/ufshcd-pltfrm.c static int ufshcd_parse_clock_info(struct ufs_hba *hba) · line 114

Quoted 4 lines · Liang He
drivers/ufs/host/ufshcd-pltfrm.c +4 -0
+static bool is_of_parse_phandle(const struct device_node *np,
+						const char *phandle_name,
+						int index)
+{

The function name sounds weird to me. Would phandle_exists() perhaps be a better name?

Thanks,

Bart.

author
#2 lore raw
Quoted 9 lines · Bart Van Assche

drivers/ufs/host/ufshcd-pltfrm.c static int ufshcd_parse_clock_info(struct ufs_hba *hba) · line 114

Quoted 4 lines · Liang He
drivers/ufs/host/ufshcd-pltfrm.c +4 -0
+static bool is_of_parse_phandle(const struct device_node *np,
+						const char *phandle_name,
+						int index)
+{

The function name sounds weird to me. Would phandle_exists() perhaps be a better name?

Quoted 4 lines

Thanks,

Bart.

Thanks, Bart

I will send a new version with above name.

Thanks again,

Liang