Unverified Commit 16a0cbac authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!14201 【OLK-6.6】 drivers: arch_topology: Refactor do-while loops

Merge Pull Request from: @linhongye 
 

    A bugfix of the Linux mainline version is incorporated to fix the problem that the thread number of the smt control is incorrectly written in DT mode.
    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.

mainline inclusion
from mainline-v6.10-rc2
commit 97b1974547c517d8b5cba1fa0cc7213399ff0d2c
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBBU4K 
 
Link:https://gitee.com/openeuler/kernel/pulls/14201

 

Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents 9e7f01f2 49a0f287
Loading
Loading
Loading
Loading
+55 −52
Original line number Diff line number Diff line
@@ -527,7 +527,9 @@ static int __init parse_core(struct device_node *core, int package_id,
	do {
		snprintf(name, sizeof(name), "thread%d", i);
		t = of_get_child_by_name(core, name);
		if (t) {
		if (!t)
			break;

		leaf = false;
		cpu = get_cpu_for_node(t);
		if (cpu >= 0) {
@@ -541,9 +543,8 @@ static int __init parse_core(struct device_node *core, int package_id,
			return -EINVAL;
		}
		of_node_put(t);
		}
		i++;
	} while (t);
	} while (1);

	/*
	 * We've already gotten threads number in this core, update the SMT
@@ -590,7 +591,9 @@ static int __init parse_cluster(struct device_node *cluster, int package_id,
	do {
		snprintf(name, sizeof(name), "cluster%d", i);
		c = of_get_child_by_name(cluster, name);
		if (c) {
		if (!c)
			break;

		leaf = false;
		ret = parse_cluster(c, package_id, i, depth + 1);
		if (depth > 0)
@@ -598,28 +601,27 @@ static int __init parse_cluster(struct device_node *cluster, int package_id,
		of_node_put(c);
		if (ret != 0)
			return ret;
		}
		i++;
	} while (c);
	} while (1);

	/* Now check for cores */
	i = 0;
	do {
		snprintf(name, sizeof(name), "core%d", i);
		c = of_get_child_by_name(cluster, name);
		if (c) {
		if (!c)
			break;

		has_cores = true;

		if (depth == 0) {
				pr_err("%pOF: cpu-map children should be clusters\n",
				       c);
			pr_err("%pOF: cpu-map children should be clusters\n", c);
			of_node_put(c);
			return -EINVAL;
		}

		if (leaf) {
				ret = parse_core(c, package_id, cluster_id,
						 core_id++);
			ret = parse_core(c, package_id, cluster_id, core_id++);
		} else {
			pr_err("%pOF: Non-leaf cluster with core %s\n",
			       cluster, name);
@@ -629,9 +631,8 @@ static int __init parse_cluster(struct device_node *cluster, int package_id,
		of_node_put(c);
		if (ret != 0)
			return ret;
		}
		i++;
	} while (c);
	} while (1);

	if (leaf && !has_cores)
		pr_warn("%pOF: empty cluster\n", cluster);
@@ -649,15 +650,17 @@ static int __init parse_socket(struct device_node *socket)
	do {
		snprintf(name, sizeof(name), "socket%d", package_id);
		c = of_get_child_by_name(socket, name);
		if (c) {
		if (!c)
			break;

		has_socket = true;
		ret = parse_cluster(c, package_id, -1, 0);
		of_node_put(c);
		if (ret != 0)
			return ret;
		}

		package_id++;
	} while (c);
	} while (1);

	if (!has_socket)
		ret = parse_cluster(socket, 0, -1, 0);