Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: aa4976130934 ("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>

authored by

Liang He and committed by
Martin K. Petersen
a3435afb 0fde22c5

+13 -2
+13 -2
drivers/ufs/host/ufshcd-pltfrm.c
··· 108 108 return ret; 109 109 } 110 110 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 + 111 122 #define MAX_PROP_SIZE 32 112 123 static int ufshcd_populate_vreg(struct device *dev, const char *name, 113 - struct ufs_vreg **out_vreg) 124 + struct ufs_vreg **out_vreg) 114 125 { 115 126 char prop_name[MAX_PROP_SIZE]; 116 127 struct ufs_vreg *vreg = NULL; ··· 133 122 } 134 123 135 124 snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", name); 136 - if (!of_parse_phandle(np, prop_name, 0)) { 125 + if (!phandle_exists(np, prop_name, 0)) { 137 126 dev_info(dev, "%s: Unable to find %s regulator, assuming enabled\n", 138 127 __func__, prop_name); 139 128 goto out;