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

Configure Feed

Select the types of activity you want to include in your feed.

drivers: arch_topology: Refactor do-while loops

Refactor do-while loops to move break condition within the loop's scope.
This modification is in preparation to move the declaration of the
device_node directly within the loop and take advantage of the automatic
cleanup feature provided by the __free(device_node) attribute.

Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Vincenzo Mezzela <vincenzo.mezzela@gmail.com>
Link: https://lore.kernel.org/r/20240607163350.392971-2-vincenzo.mezzela@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Vincenzo Mezzela and committed by
Greg Kroah-Hartman
97b19745 d7d3ae44

+55 -52
+55 -52
drivers/base/arch_topology.c
··· 543 543 do { 544 544 snprintf(name, sizeof(name), "thread%d", i); 545 545 t = of_get_child_by_name(core, name); 546 - if (t) { 547 - leaf = false; 548 - cpu = get_cpu_for_node(t); 549 - if (cpu >= 0) { 550 - cpu_topology[cpu].package_id = package_id; 551 - cpu_topology[cpu].cluster_id = cluster_id; 552 - cpu_topology[cpu].core_id = core_id; 553 - cpu_topology[cpu].thread_id = i; 554 - } else if (cpu != -ENODEV) { 555 - pr_err("%pOF: Can't get CPU for thread\n", t); 556 - of_node_put(t); 557 - return -EINVAL; 558 - } 546 + if (!t) 547 + break; 548 + 549 + leaf = false; 550 + cpu = get_cpu_for_node(t); 551 + if (cpu >= 0) { 552 + cpu_topology[cpu].package_id = package_id; 553 + cpu_topology[cpu].cluster_id = cluster_id; 554 + cpu_topology[cpu].core_id = core_id; 555 + cpu_topology[cpu].thread_id = i; 556 + } else if (cpu != -ENODEV) { 557 + pr_err("%pOF: Can't get CPU for thread\n", t); 559 558 of_node_put(t); 559 + return -EINVAL; 560 560 } 561 + of_node_put(t); 561 562 i++; 562 - } while (t); 563 + } while (1); 563 564 564 565 cpu = get_cpu_for_node(core); 565 566 if (cpu >= 0) { ··· 600 599 do { 601 600 snprintf(name, sizeof(name), "cluster%d", i); 602 601 c = of_get_child_by_name(cluster, name); 603 - if (c) { 604 - leaf = false; 605 - ret = parse_cluster(c, package_id, i, depth + 1); 606 - if (depth > 0) 607 - pr_warn("Topology for clusters of clusters not yet supported\n"); 608 - of_node_put(c); 609 - if (ret != 0) 610 - return ret; 611 - } 602 + if (!c) 603 + break; 604 + 605 + leaf = false; 606 + ret = parse_cluster(c, package_id, i, depth + 1); 607 + if (depth > 0) 608 + pr_warn("Topology for clusters of clusters not yet supported\n"); 609 + of_node_put(c); 610 + if (ret != 0) 611 + return ret; 612 612 i++; 613 - } while (c); 613 + } while (1); 614 614 615 615 /* Now check for cores */ 616 616 i = 0; 617 617 do { 618 618 snprintf(name, sizeof(name), "core%d", i); 619 619 c = of_get_child_by_name(cluster, name); 620 - if (c) { 621 - has_cores = true; 620 + if (!c) 621 + break; 622 622 623 - if (depth == 0) { 624 - pr_err("%pOF: cpu-map children should be clusters\n", 625 - c); 626 - of_node_put(c); 627 - return -EINVAL; 628 - } 623 + has_cores = true; 629 624 630 - if (leaf) { 631 - ret = parse_core(c, package_id, cluster_id, 632 - core_id++); 633 - } else { 634 - pr_err("%pOF: Non-leaf cluster with core %s\n", 635 - cluster, name); 636 - ret = -EINVAL; 637 - } 638 - 625 + if (depth == 0) { 626 + pr_err("%pOF: cpu-map children should be clusters\n", c); 639 627 of_node_put(c); 640 - if (ret != 0) 641 - return ret; 628 + return -EINVAL; 642 629 } 630 + 631 + if (leaf) { 632 + ret = parse_core(c, package_id, cluster_id, core_id++); 633 + } else { 634 + pr_err("%pOF: Non-leaf cluster with core %s\n", 635 + cluster, name); 636 + ret = -EINVAL; 637 + } 638 + 639 + of_node_put(c); 640 + if (ret != 0) 641 + return ret; 643 642 i++; 644 - } while (c); 643 + } while (1); 645 644 646 645 if (leaf && !has_cores) 647 646 pr_warn("%pOF: empty cluster\n", cluster); ··· 659 658 do { 660 659 snprintf(name, sizeof(name), "socket%d", package_id); 661 660 c = of_get_child_by_name(socket, name); 662 - if (c) { 663 - has_socket = true; 664 - ret = parse_cluster(c, package_id, -1, 0); 665 - of_node_put(c); 666 - if (ret != 0) 667 - return ret; 668 - } 661 + if (!c) 662 + break; 663 + 664 + has_socket = true; 665 + ret = parse_cluster(c, package_id, -1, 0); 666 + of_node_put(c); 667 + if (ret != 0) 668 + return ret; 669 + 669 670 package_id++; 670 - } while (c); 671 + } while (1); 671 672 672 673 if (!has_socket) 673 674 ret = parse_cluster(socket, 0, -1, 0);