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

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 <javier.carrasco.cruz@gmail.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

authored by

Javier Carrasco and committed by
Viresh Kumar
9e697efe d01c84b9

+7 -18
+7 -18
drivers/cpufreq/qcom-cpufreq-nvmem.c
··· 455 455 { 456 456 struct qcom_cpufreq_drv *drv; 457 457 struct nvmem_cell *speedbin_nvmem; 458 - struct device_node *np; 459 458 struct device *cpu_dev; 460 459 char pvs_name_buffer[] = "speedXX-pvsXX-vXX"; 461 460 char *pvs_name = pvs_name_buffer; ··· 466 467 if (!cpu_dev) 467 468 return -ENODEV; 468 469 469 - np = dev_pm_opp_of_get_opp_desc_node(cpu_dev); 470 + struct device_node *np __free(device_node) = 471 + dev_pm_opp_of_get_opp_desc_node(cpu_dev); 470 472 if (!np) 471 473 return -ENOENT; 472 474 473 475 ret = of_device_is_compatible(np, "operating-points-v2-kryo-cpu") || 474 476 of_device_is_compatible(np, "operating-points-v2-krait-cpu"); 475 - if (!ret) { 476 - of_node_put(np); 477 + if (!ret) 477 478 return -ENOENT; 478 - } 479 479 480 480 drv = devm_kzalloc(&pdev->dev, struct_size(drv, cpus, num_possible_cpus()), 481 481 GFP_KERNEL); 482 - if (!drv) { 483 - of_node_put(np); 482 + if (!drv) 484 483 return -ENOMEM; 485 - } 486 484 487 485 match = pdev->dev.platform_data; 488 486 drv->data = match->data; 489 - if (!drv->data) { 490 - of_node_put(np); 487 + if (!drv->data) 491 488 return -ENODEV; 492 - } 493 489 494 490 if (drv->data->get_version) { 495 491 speedbin_nvmem = of_nvmem_cell_get(np, NULL); 496 - if (IS_ERR(speedbin_nvmem)) { 497 - of_node_put(np); 492 + if (IS_ERR(speedbin_nvmem)) 498 493 return dev_err_probe(cpu_dev, PTR_ERR(speedbin_nvmem), 499 494 "Could not get nvmem cell\n"); 500 - } 501 495 502 496 ret = drv->data->get_version(cpu_dev, 503 497 speedbin_nvmem, &pvs_name, drv); 504 498 if (ret) { 505 - of_node_put(np); 506 499 nvmem_cell_put(speedbin_nvmem); 507 500 return ret; 508 501 } 509 502 nvmem_cell_put(speedbin_nvmem); 510 503 } 511 - of_node_put(np); 512 504 513 505 for_each_possible_cpu(cpu) { 514 506 struct device **virt_devs = NULL; ··· 635 645 */ 636 646 static int __init qcom_cpufreq_init(void) 637 647 { 638 - struct device_node *np = of_find_node_by_path("/"); 648 + struct device_node *np __free(device_node) = of_find_node_by_path("/"); 639 649 const struct of_device_id *match; 640 650 int ret; 641 651 ··· 643 653 return -ENODEV; 644 654 645 655 match = of_match_node(qcom_cpufreq_match_list, np); 646 - of_node_put(np); 647 656 if (!match) 648 657 return -ENODEV; 649 658