[PATCH net] tools: ynl: reject missing regen path argument

From: Zhiqi Zhang

Date: Wed Nov 25 2026 - 02:04:12 EST


ynl-regen.sh expects -p to be followed by a path. If -p is
passed without an argument, $2 is empty and shift 2 fails without
consuming $1. The option parser then keeps looping on -p until
the caller kills the script.

I found the issue by manual code inspection and validated it with:

timeout 2s bash tools/net/ynl/ynl-regen.sh -p

which used to time out with exit code 124.

Reject -p without an argument before shifting. Also stop if the
selected path cannot be entered, so the script does not continue
from an unintended directory after a bad -p path.

GPT wrote the code change; I reviewed and tested it.

Tested with:

timeout 2s bash tools/net/ynl/ynl-regen.sh -p
timeout 2s bash tools/net/ynl/ynl-regen.sh -p \
/definitely/not/a/kernel/tree
bash -n tools/net/ynl/ynl-regen.sh
scripts/checkpatch.pl --strict --file tools/net/ynl/ynl-regen.sh

Fixes: 25b5a2a1905f ("ynl: regenerate all headers")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@xxxxxxxxx>
---
tools/net/ynl/ynl-regen.sh | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/net/ynl/ynl-regen.sh b/tools/net/ynl/ynl-regen.sh
index d9809276db..524fadb770 100755
--- a/tools/net/ynl/ynl-regen.sh
+++ b/tools/net/ynl/ynl-regen.sh
@@ -9,13 +9,20 @@ search=
while [ ! -z "$1" ]; do
case "$1" in
-f ) force=yes; shift ;;
- -p ) search=$2; shift 2 ;;
+ -p )
+ if [ $# -lt 2 ]; then
+ echo "Option -p requires a path" >&2
+ exit 1
+ fi
+ search=$2
+ shift 2
+ ;;
* ) echo "Unrecognized option '$1'"; exit 1 ;;
esac
done

KDIR=$(dirname $(dirname $(dirname $(dirname $(realpath $0)))))
-pushd ${search:-$KDIR} >>/dev/null
+pushd "${search:-$KDIR}" >>/dev/null || exit 1

files=$(git grep --files-with-matches '^/\* YNL-GEN \(kernel\|uapi\|user\)')
for f in $files; do

base-commit: 7ccb044c27720d48175577080b851f047ddcfd1c
--
2.54.0 (Apple Git-157)