All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] of_numa: fix return -EINVAL when numa-node-id is not found in last node
@ 2026-06-21 14:39 Sang-Heon Jeon
  2026-06-23  1:42 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Sang-Heon Jeon @ 2026-06-21 14:39 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Sang-Heon Jeon, Andrew Morton, Dan Williams, David Hildenbrand,
	devicetree, Jonathan Cameron, Mike Rapoport (Microsoft)

When the numa-node-id property is not found in the last memory node,
of_property_read_u32() returns -EINVAL, which then becomes the return
value of of_numa_parse_memory_nodes(), even though earlier memory nodes
were parsed successfully.

Commit 7e488677a54a ("of, numa: return -EINVAL when no numa-node-id is
found") meant -EINVAL to be returned only when the numa-node-id property
is not found at all, not when it is found in an earlier memory node but
not in the last.

Check whether at least one memory node was parsed successfully, and return
0 in that case, -EINVAL otherwise, so the return value of
of_property_read_u32() for the last memory node no longer corrupts the
overall return value.

Also include other minor changes for readability improvement with no
functional change.

Fixes: 7e488677a54a ("of, numa: return -EINVAL when no numa-node-id is found")
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
QEMU-based test results

DTB memory nodes defined in DT
  - memory@80000000 (0x80000000-0x9fffffff) numa-node-id = <0>
  - memory@c0000000 (0xc0000000-0xdfffffff) numa-node-id = <0>
  - memory@e0000000 (0xe0000000-0xffffffff) numa-node-id = <1>
  - memory@a0000000 (0xa0000000-0xbfffffff) (no numa-node-id)

1) AS-IS (before fix)
[    0.000000] NUMA: Faking a node at [mem 0x0000000080000000-0x00000000ffffffff]
[    0.069152] futex hash table entries: 512 (32768 bytes on 1 NUMA nodes, total 32 KiB, linear).

...

2) TO-BE (after fix)
[    0.000000] NUMA: Node 0 [mem 0x80000000-0x9fffffff] + [mem 0xc0000000-0xdfffffff] -> [mem 0x80000000-0xdfffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080000000-0x00000000dfffffff]
[    0.000000] Initmem setup node 1 [mem 0x00000000e0000000-0x00000000ffffffff]
[    0.076854] futex hash table entries: 256 (16384 bytes on 2 NUMA nodes, total 32 KiB, linear).

...

Tested the scenarios below to confirm no regression, and all produced
the same result on AS-IS and TO-BE:
  - all / no memory nodes tagged
  - untagged memory node exist, but not last
  - empty / out-of-range numa-node-id
  - memory node without reg

---
 drivers/of/of_numa.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c
index cd2dc8e825c9..13f2f6d238c9 100644
--- a/drivers/of/of_numa.c
+++ b/drivers/of/of_numa.c
@@ -42,7 +42,8 @@ static int __init of_numa_parse_memory_nodes(void)
 	struct device_node *np = NULL;
 	struct resource rsrc;
 	u32 nid;
-	int i, r = -EINVAL;
+	int i, r;
+	bool found = false;
 
 	for_each_node_by_type(np, "memory") {
 		r = of_property_read_u32(np, "numa-node-id", &nid);
@@ -53,26 +54,32 @@ static int __init of_numa_parse_memory_nodes(void)
 			 * "numa-node-id" property
 			 */
 			continue;
+		if (r)
+			goto err;
 
 		if (nid >= MAX_NUMNODES) {
 			pr_warn("Node id %u exceeds maximum value\n", nid);
-			r = -EINVAL;
+			goto err;
 		}
 
-		for (i = 0; !r && !of_address_to_resource(np, i, &rsrc); i++) {
+		for (i = 0; !of_address_to_resource(np, i, &rsrc); i++) {
 			r = numa_add_memblk(nid, rsrc.start, rsrc.end + 1);
-			if (!r)
-				node_set(nid, numa_nodes_parsed);
+			if (r)
+				goto err;
+			node_set(nid, numa_nodes_parsed);
 		}
+		if (!i)
+			goto err;
 
-		if (!i || r) {
-			of_node_put(np);
-			pr_err("bad property in memory node\n");
-			return r ? : -EINVAL;
-		}
+		found = true;
 	}
 
-	return r;
+	return found ? 0 : -EINVAL;
+
+err:
+	of_node_put(np);
+	pr_err("bad property in memory node\n");
+	return r ?: -EINVAL;
 }
 
 static int __init of_numa_parse_distance_map_v1(struct device_node *map)
-- 
2.43.0


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

* Re: [PATCH] of_numa: fix return -EINVAL when numa-node-id is not found in last node
  2026-06-21 14:39 [PATCH] of_numa: fix return -EINVAL when numa-node-id is not found in last node Sang-Heon Jeon
@ 2026-06-23  1:42 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2026-06-23  1:42 UTC (permalink / raw)
  To: Sang-Heon Jeon
  Cc: Saravana Kannan, Andrew Morton, Dan Williams, David Hildenbrand,
	devicetree, Jonathan Cameron, Mike Rapoport (Microsoft)

On Sun, Jun 21, 2026 at 11:39:18PM +0900, Sang-Heon Jeon wrote:
> When the numa-node-id property is not found in the last memory node,
> of_property_read_u32() returns -EINVAL, which then becomes the return
> value of of_numa_parse_memory_nodes(), even though earlier memory nodes
> were parsed successfully.
> 
> Commit 7e488677a54a ("of, numa: return -EINVAL when no numa-node-id is
> found") meant -EINVAL to be returned only when the numa-node-id property
> is not found at all, not when it is found in an earlier memory node but
> not in the last.
> 
> Check whether at least one memory node was parsed successfully, and return
> 0 in that case, -EINVAL otherwise, so the return value of
> of_property_read_u32() for the last memory node no longer corrupts the
> overall return value.

IDK, it's arguable that an incomplete DT isn't valid and something we 
need to support. Is missing numa-node-id valid or it's just better to 
have at least partially 
configured NUMA nodes?

Rob

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

end of thread, other threads:[~2026-06-23  1:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-21 14:39 [PATCH] of_numa: fix return -EINVAL when numa-node-id is not found in last node Sang-Heon Jeon
2026-06-23  1:42 ` Rob Herring

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.