Skip to content

Commit a3435af

Browse files
windhlmartinkpetersen
authored andcommitted
scsi: ufs: host: 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. Link: https://lore.kernel.org/r/20220719071529.1081166-1-windhl@126.com Fixes: aa49761 ("ufs: Add regulator enable support") Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Liang He <windhl@126.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 0fde22c commit a3435af

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/ufs/host/ufshcd-pltfrm.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,20 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
108108
return ret;
109109
}
110110

111+
static bool phandle_exists(const struct device_node *np,
112+
const char *phandle_name, int index)
113+
{
114+
struct device_node *parse_np = of_parse_phandle(np, phandle_name, index);
115+
116+
if (parse_np)
117+
of_node_put(parse_np);
118+
119+
return parse_np != NULL;
120+
}
121+
111122
#define MAX_PROP_SIZE 32
112123
static int ufshcd_populate_vreg(struct device *dev, const char *name,
113-
struct ufs_vreg **out_vreg)
124+
struct ufs_vreg **out_vreg)
114125
{
115126
char prop_name[MAX_PROP_SIZE];
116127
struct ufs_vreg *vreg = NULL;
@@ -122,7 +133,7 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
122133
}
123134

124135
snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", name);
125-
if (!of_parse_phandle(np, prop_name, 0)) {
136+
if (!phandle_exists(np, prop_name, 0)) {
126137
dev_info(dev, "%s: Unable to find %s regulator, assuming enabled\n",
127138
__func__, prop_name);
128139
goto out;

0 commit comments

Comments
 (0)