All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpu-topology: Skip the exist but not possible cpu nodes
@ 2020-01-02  3:24 Zeng Tao
  2020-01-06 18:42 ` Dietmar Eggemann
  2020-01-07 14:49 ` Sudeep Holla
  0 siblings, 2 replies; 9+ messages in thread
From: Zeng Tao @ 2020-01-02  3:24 UTC (permalink / raw)
  To: sudeep.holla
  Cc: linuxarm, Zeng Tao, Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel

When CONFIG_NR_CPUS is smaller than the cpu nodes defined in the device
tree, the cpu node parsing will fail. And this is not reasonable for a
legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.

Signed-off-by: Zeng Tao <prime.zeng@hisilicon.com>
---
 drivers/base/arch_topology.c | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 5fe44b3..4cddfeb 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -250,20 +250,34 @@ core_initcall(free_raw_capacity);
 #if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
 static int __init get_cpu_for_node(struct device_node *node)
 {
-	struct device_node *cpu_node;
+	struct device_node *cpu_node, *t;
 	int cpu;
+	bool found = false;
 
 	cpu_node = of_parse_phandle(node, "cpu", 0);
 	if (!cpu_node)
-		return -1;
+		return -EINVAL;
+
+	for_each_of_cpu_node(t)
+		if (t == cpu_node) {
+			found = true;
+			break;
+		}
+
+	if (!found) {
+		pr_crit("Unable to find CPU node for %pOF\n", cpu_node);
+		return -EINVAL;
+	}
 
 	cpu = of_cpu_node_to_id(cpu_node);
 	if (cpu >= 0)
 		topology_parse_cpu_capacity(cpu_node, cpu);
-	else
-		pr_crit("Unable to find CPU node for %pOF\n", cpu_node);
+	else {
+		pr_warn("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
+			cpu_node, cpumask_pr_args(cpu_possible_mask));
+		cpu = -ENODEV;
+	}
 
-	of_node_put(cpu_node);
 	return cpu;
 }
 
@@ -287,10 +301,13 @@ static int __init parse_core(struct device_node *core, int package_id,
 				cpu_topology[cpu].core_id = core_id;
 				cpu_topology[cpu].thread_id = i;
 			} else {
-				pr_err("%pOF: Can't get CPU for thread\n",
-				       t);
+				if (cpu != -ENODEV)
+					pr_err("%pOF: Can't get CPU for thread\n",
+					       t);
+				else
+					cpu = 0;
 				of_node_put(t);
-				return -EINVAL;
+				return cpu;
 			}
 			of_node_put(t);
 		}
@@ -307,7 +324,7 @@ static int __init parse_core(struct device_node *core, int package_id,
 
 		cpu_topology[cpu].package_id = package_id;
 		cpu_topology[cpu].core_id = core_id;
-	} else if (leaf) {
+	} else if (leaf && cpu != -ENODEV) {
 		pr_err("%pOF: Can't get CPU for leaf core\n", core);
 		return -EINVAL;
 	}
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-01-11  2:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-02  3:24 [PATCH] cpu-topology: Skip the exist but not possible cpu nodes Zeng Tao
2020-01-06 18:42 ` Dietmar Eggemann
2020-01-07  1:35   ` Zengtao (B)
2020-01-07 13:12     ` Dietmar Eggemann
2020-01-08  2:01       ` Zengtao (B)
2020-01-07 14:49 ` Sudeep Holla
2020-01-08  1:57   ` Zengtao (B)
2020-01-10 11:16     ` Sudeep Holla
2020-01-11  2:03       ` Zengtao (B)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.