From: Taylor Bates <tmbates12@gmail.com>
To: Donald Hunter <donald.hunter@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Jiri Pirko <jiri@resnulli.us>,
Stanislav Fomichev <sdf@fomichev.me>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Taylor Bates <tmbates12@gmail.com>
Subject: [PATCH net-next 3/4] tools: ynl: stop find_kernel_root() spinning at the filesystem root
Date: Tue, 08 Sep 2026 19:45:09 -0400 [thread overview]
Message-ID: <20260908-ynl-robustness-v1-3-f255214c0f30@gmail.com> (raw)
In-Reply-To: <20260908-ynl-robustness-v1-0-f255214c0f30@gmail.com>
In the current pyynl tooling, the find_kernel_root() function
contains a loop that climbs up the directory tree relative to the
spec file until it finds a MAINTAINERS file. If ynl_gen_c.py is run
in-tree it terminates properly in the root of the kernel tree.
The relative directory returned is then used to build the provenance
comment. The path of the root directory that it terminates at is
thrown away immediately at the call site:
_, spec_kernel = find_kernel_root(args.spec)
However, if it is run out-of-tree and does not find a MAINTAINERS
file in any of the directories, find_kernel_root() reaches "/".
Since os.path.dirname() is idempotent at "/", the while True: has no
exit.
This can be reproduced on today's tree if the specs are copied to
a directory outside of the kernel tree:
mkdir -p /tmp/ynl-oot/specs
cp Documentation/netlink/netlink-raw.yaml /tmp/ynl-oot/
cp Documentation/netlink/specs/rt-link.yaml /tmp/ynl-oot/specs/
tools/net/ynl/pyynl/ynl_gen_c.py --spec /tmp/ynl-oot/specs/rt-link.yaml \
--mode uapi --header
The fallback implemented in this patch still
provides a usable output:
/* Do not edit directly, auto-generated from: */
/* tmp/ynl-oot/specs/rt-link.yaml */
Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink")
Signed-off-by: Taylor Bates <tmbates12@gmail.com>
---
tools/net/ynl/pyynl/ynl_gen_c.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 2b3483db1b60..1c422141d2d7 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -3449,7 +3449,12 @@ def find_kernel_root(full_path):
sub_path = ''
while True:
sub_path = os.path.join(os.path.basename(full_path), sub_path)
- full_path = os.path.dirname(full_path)
+ parent = os.path.dirname(full_path)
+ if parent == full_path:
+ # Reached the filesystem root without finding a kernel tree, fall
+ # back to the path given.
+ return None, sub_path[:-1]
+ full_path = parent
maintainers = os.path.join(full_path, "MAINTAINERS")
if os.path.exists(maintainers):
return full_path, sub_path[:-1]
--
2.55.0
next prev parent reply other threads:[~2026-09-08 23:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 23:45 [PATCH net-next 0/4] netlink: fix ynl spec tooling robustness bugs Taylor Bates
2026-09-08 23:45 ` [PATCH net-next 1/4] netlink: specs: fix duplicate if/then keys in netlink-raw schema Taylor Bates
2026-09-08 23:45 ` [PATCH net-next 2/4] tools: ynl: reject zero-length attributes instead of looping forever Taylor Bates
2026-09-11 2:25 ` Jakub Kicinski
2026-09-08 23:45 ` Taylor Bates [this message]
2026-09-11 2:26 ` [PATCH net-next 3/4] tools: ynl: stop find_kernel_root() spinning at the filesystem root Jakub Kicinski
2026-09-08 23:45 ` [PATCH net-next 4/4] tools: ynl: fix uapi generation for anonymous enums with documented entries Taylor Bates
2026-09-11 2:27 ` Jakub Kicinski
2026-09-11 2:23 ` [PATCH net-next 0/4] netlink: fix ynl spec tooling robustness bugs Jakub Kicinski
2026-09-12 17:35 ` tmbates12
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=20260908-ynl-robustness-v1-3-f255214c0f30@gmail.com \
--to=tmbates12@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
/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