Skip to contentSkip to conversation

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

PATCH Superseded Liang He 2 participants 8 messages Jul 15, 2022 – Jul 20, 2022 SCSI

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

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

---
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/[email protected]/

 drivers/ufs/host/ufshcd-pltfrm.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/ufs/host/ufshcd-pltfrm.c +16 -1
index e7332cc65b1f..46ded7813c42 100644
@@ -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;
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 113

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

Indentation of the arguments now looks really odd :-(

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

Quoted 11 lines
drivers/ufs/host/ufshcd-pltfrm.c +11 -0
+{
+	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;
+}

The 'ret' variable is not necessary. If "return ret" is changed into "return parse_np" then the variable 'ret' can be left out.

Thanks,

Bart.

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

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

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

Indentation of the arguments now looks really odd :-(

Yes, Bart, I also wonder this coding style, however I learned that from the definition of 'of_parse_phandle' in of.h.

Is it OK if I put all of them in one line?

Thanks,

Quoted 16 lines

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

Quoted 12 lines
drivers/ufs/host/ufshcd-pltfrm.c +11 -0
+{
+	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;
+}

The 'ret' variable is not necessary. If "return ret" is changed into "return parse_np" then the variable 'ret' can be left out.

OK, I will use 'return parse_np' in new version when you confirm above coding style.

Quoted 3 lines

Thanks,

Bart.

Thanks,

Liang

#3 lore raw
Quoted 8 lines · Liang He
Quoted 6 lines · Bart Van Assche

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

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

Indentation of the arguments now looks really odd :-(

Quoted 4 lines

Yes, Bart, I also wonder this coding style, however I learned that from the definition of 'of_parse_phandle' in of.h.

Is it OK if I put all of them in one line?

No. From Documentation/process/coding-style.rst (please read that document in its entirety): "The preferred limit on the length of a single line is 80 columns. [...] A very commonly used style is to align descendants to a function open parenthesis."

Consider to use the following formatting:

static bool phandle_exists(const struct device_node *np,
const char *phandle_name, int index)

{
	[ ... ]
}
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
drivers/ufs/host/ufshcd-pltfrm.c +6 -0
+{
+	struct device_node *parse_np = of_parse_phandle(np, phandle_name, index);
+	bool ret = false;
+
+	if (parse_np) {
+		ret = true;
Quoted 9 lines

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

Quoted 5 lines
drivers/ufs/host/ufshcd-pltfrm.c +5 -0
+		of_node_put(parse_np);
+	}
+
+	return ret;
+}

The 'ret' variable is not necessary. If "return ret" is changed into "return parse_np" then the variable 'ret' can be left out.

Quoted 1 line

OK, I will use 'return parse_np' in new version when you confirm above coding style.

You may want to use "return parse_np != NULL" if you want to be sure that nobody else will complain about an implicit conversion of a pointer to a boolean type.

Thanks,

Bart.

author
#4 lore raw
Quoted 19 lines · Bart Van Assche
Quoted 8 lines · Liang He
Quoted 6 lines · Bart Van Assche

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

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

Indentation of the arguments now looks really odd :-(

Quoted 4 lines

Yes, Bart, I also wonder this coding style, however I learned that from the definition of 'of_parse_phandle' in of.h.

Is it OK if I put all of them in one line?

No. From Documentation/process/coding-style.rst (please read that document in its entirety): "The preferred limit on the length of a single line is 80 columns. [...] A very commonly used style is to align descendants to a function open parenthesis."

Quoted 8 lines

Consider to use the following formatting:

static bool phandle_exists(const struct device_node *np,
const char *phandle_name, int index)

{
	[ ... ]
}

Thanks very much, Bart,

I will follow your advice and I will read carefully the Documentation/process/coding-style.rst

Liang

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

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

Quoted 11 lines
drivers/ufs/host/ufshcd-pltfrm.c +11 -0
+{
+	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;
+}

The 'ret' variable is not necessary. If "return ret" is changed into "return parse_np" then the variable 'ret' can be left out.

Quoted 6 lines
Quoted 1 line

OK, I will use 'return parse_np' in new version when you confirm above coding style.

You may want to use "return parse_np != NULL" if you want to be sure that nobody else will complain about an implicit conversion of a pointer to a boolean type.

OK, I think 'return parse_np != NULL' is better.

I will prepare new version patch soon.

Quoted 3 lines

Thanks,

Bart.

Thanks,
Liang

author
#5 lore raw
In reply to Bart Van Assche
Quoted 19 lines · Bart Van Assche
Quoted 8 lines · Liang He
Quoted 6 lines · Bart Van Assche

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

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

Indentation of the arguments now looks really odd :-(

Quoted 4 lines

Yes, Bart, I also wonder this coding style, however I learned that from the definition of 'of_parse_phandle' in of.h.

Is it OK if I put all of them in one line?

No. From Documentation/process/coding-style.rst (please read that document in its entirety): "The preferred limit on the length of a single line is 80 columns. [...] A very commonly used style is to align descendants to a function open parenthesis."

Quoted 8 lines

Consider to use the following formatting:

static bool phandle_exists(const struct device_node *np,
const char *phandle_name, int index)

{
	[ ... ]
}

Hi, Bart,

Can you help me as I have a trouble about the indentation.

When I align descendants to a function open parenthesis in VIM editor, but when I generate the patch, I find the second line always missing one space in patch format. So is there any problem if I send this patch?

I make sure that the alignment in VIM is OK.

Thanks,
Liang

Quoted 25 lines
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
drivers/ufs/host/ufshcd-pltfrm.c +6 -0
+{
+	struct device_node *parse_np = of_parse_phandle(np, phandle_name, index);
+	bool ret = false;
+
+	if (parse_np) {
+		ret = true;
Quoted 9 lines

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

Quoted 5 lines
drivers/ufs/host/ufshcd-pltfrm.c +5 -0
+		of_node_put(parse_np);
+	}
+
+	return ret;
+}

The 'ret' variable is not necessary. If "return ret" is changed into "return parse_np" then the variable 'ret' can be left out.

Quoted 1 line

OK, I will use 'return parse_np' in new version when you confirm above coding style.

You may want to use "return parse_np != NULL" if you want to be sure that nobody else will complain about an implicit conversion of a pointer to a boolean type.

Thanks,

Bart.

#6 lore raw
Quoted 7 lines · Liang He

Can you help me as I have a trouble about the indentation.

When I align descendants to a function open parenthesis in VIM editor, but when I generate the patch, I find the second line always missing one space in patch format. So is there any problem if I send this patch?

I make sure that the alignment in VIM is OK.

Hi Liang,

Please don't worry about this. When a code change is converted into a patch, a single character is inserted at the start of each line (plus, minus or space). That makes code that is indented with tabs look weird. This is normal.

Bart.

author
#7 lore raw
Quoted 9 lines · Bart Van Assche
Quoted 7 lines · Liang He

Can you help me as I have a trouble about the indentation.

When I align descendants to a function open parenthesis in VIM editor, but when I generate the patch, I find the second line always missing one space in patch format. So is there any problem if I send this patch?

I make sure that the alignment in VIM is OK.

Quoted 8 lines

Hi Liang,

Please don't worry about this. When a code change is converted into a patch, a single character is inserted at the start of each line (plus, minus or space). That makes code that is indented with tabs look weird. This is normal.

Bart.

Thanks very much for all your help and your effort to review my code.

Liang