Skip to content

Commit 9e697ef

Browse files
javiercarrascocruzvireshk
authored andcommitted
cpufreq: qcom-nvmem: eliminate uses of of_node_put()
Make use of the __free() macro to automate memory deallocation when the existing device nodes get out of scope, removing the need for of_node_put() and therefore increasing code safety if more error paths are added to the driver, which could miss the required of_node_put() as it already occurred with commit '57f2f8b4aa0c ("cpufreq: qcom: Refactor the driver to make it easier to extend")'. Signed-off-by: Javier Carrasco <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent d01c84b commit 9e697ef

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

drivers/cpufreq/qcom-cpufreq-nvmem.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
455455
{
456456
struct qcom_cpufreq_drv *drv;
457457
struct nvmem_cell *speedbin_nvmem;
458-
struct device_node *np;
459458
struct device *cpu_dev;
460459
char pvs_name_buffer[] = "speedXX-pvsXX-vXX";
461460
char *pvs_name = pvs_name_buffer;
@@ -467,49 +466,40 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
467466
if (!cpu_dev)
468467
return -ENODEV;
469468

470-
np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
469+
struct device_node *np __free(device_node) =
470+
dev_pm_opp_of_get_opp_desc_node(cpu_dev);
471471
if (!np)
472472
return -ENOENT;
473473

474474
ret = of_device_is_compatible(np, "operating-points-v2-kryo-cpu") ||
475475
of_device_is_compatible(np, "operating-points-v2-krait-cpu");
476-
if (!ret) {
477-
of_node_put(np);
476+
if (!ret)
478477
return -ENOENT;
479-
}
480478

481479
drv = devm_kzalloc(&pdev->dev, struct_size(drv, cpus, num_possible_cpus()),
482480
GFP_KERNEL);
483-
if (!drv) {
484-
of_node_put(np);
481+
if (!drv)
485482
return -ENOMEM;
486-
}
487483

488484
match = pdev->dev.platform_data;
489485
drv->data = match->data;
490-
if (!drv->data) {
491-
of_node_put(np);
486+
if (!drv->data)
492487
return -ENODEV;
493-
}
494488

495489
if (drv->data->get_version) {
496490
speedbin_nvmem = of_nvmem_cell_get(np, NULL);
497-
if (IS_ERR(speedbin_nvmem)) {
498-
of_node_put(np);
491+
if (IS_ERR(speedbin_nvmem))
499492
return dev_err_probe(cpu_dev, PTR_ERR(speedbin_nvmem),
500493
"Could not get nvmem cell\n");
501-
}
502494

503495
ret = drv->data->get_version(cpu_dev,
504496
speedbin_nvmem, &pvs_name, drv);
505497
if (ret) {
506-
of_node_put(np);
507498
nvmem_cell_put(speedbin_nvmem);
508499
return ret;
509500
}
510501
nvmem_cell_put(speedbin_nvmem);
511502
}
512-
of_node_put(np);
513503

514504
for_each_possible_cpu(cpu) {
515505
struct device **virt_devs = NULL;
@@ -645,15 +635,14 @@ MODULE_DEVICE_TABLE(of, qcom_cpufreq_match_list);
645635
*/
646636
static int __init qcom_cpufreq_init(void)
647637
{
648-
struct device_node *np = of_find_node_by_path("/");
638+
struct device_node *np __free(device_node) = of_find_node_by_path("/");
649639
const struct of_device_id *match;
650640
int ret;
651641

652642
if (!np)
653643
return -ENODEV;
654644

655645
match = of_match_node(qcom_cpufreq_match_list, np);
656-
of_node_put(np);
657646
if (!match)
658647
return -ENODEV;
659648

0 commit comments

Comments
 (0)