Skip to content

Commit fa8036e

Browse files
javiercarrascocruzvireshk
authored andcommitted
cpufreq: sun50i: replace of_node_put() with automatic cleanup handler
Make use of the __free() cleanup handler to automatically free nodes when they get out of scope. Signed-off-by: Javier Carrasco <[email protected]> Reviewed-by: Andre Przywara <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent 6282fba commit fa8036e

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

drivers/cpufreq/sun50i-cpufreq-nvmem.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ static const struct of_device_id cpu_opp_match_list[] = {
131131
static bool dt_has_supported_hw(void)
132132
{
133133
bool has_opp_supported_hw = false;
134-
struct device_node *np;
135134
struct device *cpu_dev;
136135

137136
cpu_dev = get_cpu_device(0);
138137
if (!cpu_dev)
139138
return false;
140139

141-
np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
140+
struct device_node *np __free(device_node) =
141+
dev_pm_opp_of_get_opp_desc_node(cpu_dev);
142142
if (!np)
143143
return false;
144144

@@ -149,8 +149,6 @@ static bool dt_has_supported_hw(void)
149149
}
150150
}
151151

152-
of_node_put(np);
153-
154152
return has_opp_supported_hw;
155153
}
156154

@@ -165,7 +163,6 @@ static int sun50i_cpufreq_get_efuse(void)
165163
const struct sunxi_cpufreq_data *opp_data;
166164
struct nvmem_cell *speedbin_nvmem;
167165
const struct of_device_id *match;
168-
struct device_node *np;
169166
struct device *cpu_dev;
170167
u32 *speedbin;
171168
int ret;
@@ -174,19 +171,18 @@ static int sun50i_cpufreq_get_efuse(void)
174171
if (!cpu_dev)
175172
return -ENODEV;
176173

177-
np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
174+
struct device_node *np __free(device_node) =
175+
dev_pm_opp_of_get_opp_desc_node(cpu_dev);
178176
if (!np)
179177
return -ENOENT;
180178

181179
match = of_match_node(cpu_opp_match_list, np);
182-
if (!match) {
183-
of_node_put(np);
180+
if (!match)
184181
return -ENOENT;
185-
}
182+
186183
opp_data = match->data;
187184

188185
speedbin_nvmem = of_nvmem_cell_get(np, NULL);
189-
of_node_put(np);
190186
if (IS_ERR(speedbin_nvmem))
191187
return dev_err_probe(cpu_dev, PTR_ERR(speedbin_nvmem),
192188
"Could not get nvmem cell\n");
@@ -301,14 +297,9 @@ MODULE_DEVICE_TABLE(of, sun50i_cpufreq_match_list);
301297

302298
static const struct of_device_id *sun50i_cpufreq_match_node(void)
303299
{
304-
const struct of_device_id *match;
305-
struct device_node *np;
306-
307-
np = of_find_node_by_path("/");
308-
match = of_match_node(sun50i_cpufreq_match_list, np);
309-
of_node_put(np);
300+
struct device_node *np __free(device_node) = of_find_node_by_path("/");
310301

311-
return match;
302+
return of_match_node(sun50i_cpufreq_match_list, np);
312303
}
313304

314305
/*

0 commit comments

Comments
 (0)