From: Sang-Heon Jeon <ekffu200098@gmail.com>
To: Rob Herring <robh@kernel.org>, Saravana Kannan <saravanak@kernel.org>
Cc: Sang-Heon Jeon <ekffu200098@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Dan Williams <djbw@kernel.org>,
David Hildenbrand <david@kernel.org>,
devicetree@vger.kernel.org,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>
Subject: [PATCH] of_numa: fix return -EINVAL when numa-node-id is not found in last node
Date: Sun, 21 Jun 2026 23:39:18 +0900 [thread overview]
Message-ID: <20260621143919.4176646-1-ekffu200098@gmail.com> (raw)
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
next reply other threads:[~2026-06-21 14:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-21 14:39 Sang-Heon Jeon [this message]
2026-06-23 1:42 ` [PATCH] of_numa: fix return -EINVAL when numa-node-id is not found in last node Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260621143919.4176646-1-ekffu200098@gmail.com \
--to=ekffu200098@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=djbw@kernel.org \
--cc=robh@kernel.org \
--cc=rppt@kernel.org \
--cc=saravanak@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox