From 2509879017df77a0a7478df63d3e30c193c5ed7c Mon Sep 17 00:00:00 2001 From: Stephen Nothnagel Date: Mon, 6 Apr 2026 14:54:35 -0400 Subject: serial: T8211: fix symlink collisions for multi-port USB serial adapters Multi-port USB serial adapters (e.g., MosChip MCS7840) where all ports share the same USB ID_PATH create identical symlink names in /dev/serial/by-bus/, causing only the last-enumerated port to be accessible. Split the existing catch-all rule for devices with .ID_PORT into two cases: - Port 0: keeps the base symlink name (backward compatible) - Port 1+: appends pN suffix (e.g., usb0b1.4.1p1.0p1) Devices where each port has a unique ID_PATH (e.g., FTDI FT4232H) and single-port devices are unaffected. --- src/etc/udev/rules.d/90-vyos-serial.rules | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/etc/udev/rules.d/90-vyos-serial.rules b/src/etc/udev/rules.d/90-vyos-serial.rules index 1fe7ee5ba..41cd7b381 100644 --- a/src/etc/udev/rules.d/90-vyos-serial.rules +++ b/src/etc/udev/rules.d/90-vyos-serial.rules @@ -22,7 +22,8 @@ IMPORT{builtin}="path_id", IMPORT{builtin}="usb_id" # (tr -d -) does the replacement # - Replace the first group after ":" to represent the bus relation (sed -e 0,/:/s//b/) indicated by "b" # - Replace the next group after ":" to represent the port relation (sed -e 0,/:/s//p/) indicated by "p" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="?*", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" +ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" +ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="0", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" +ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="?*", ENV{.ID_PORT}!="0", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/%cp%E{.ID_PORT}" LABEL="serial_end" -- cgit v1.2.3 From 8f5934e9a7f75a18b7399b163fe8e898a63ce77c Mon Sep 17 00:00:00 2001 From: Stephen Nothnagel Date: Wed, 8 Apr 2026 17:01:11 -0400 Subject: serial: T8211: refactor rule to reduce duplication Store the PROGRAM output in a temporary .BY_BUS ENV variable, then reference it via %E{.BY_BUS} in the SYMLINK+= assignments. This collapses the three duplicated PROGRAM pipelines into a single invocation and removes the mixed usage of $result and %c. No functional change: tested on MosChip MCS7840 (2x 4-port chips, 8 ports total), FTDI FT4232H, and Sierra EM7455 -- all symlinks identical before and after, verified with udevadm test. Reduces duplication; refactor suggested by @copilot-pull-request-reviewer on PR #5113. --- src/etc/udev/rules.d/90-vyos-serial.rules | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/etc/udev/rules.d/90-vyos-serial.rules b/src/etc/udev/rules.d/90-vyos-serial.rules index 41cd7b381..3fb34d16a 100644 --- a/src/etc/udev/rules.d/90-vyos-serial.rules +++ b/src/etc/udev/rules.d/90-vyos-serial.rules @@ -22,8 +22,9 @@ IMPORT{builtin}="path_id", IMPORT{builtin}="usb_id" # (tr -d -) does the replacement # - Replace the first group after ":" to represent the bus relation (sed -e 0,/:/s//b/) indicated by "b" # - Replace the next group after ":" to represent the port relation (sed -e 0,/:/s//p/) indicated by "p" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="0", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="?*", ENV{.ID_PORT}!="0", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/%cp%E{.ID_PORT}" +ENV{ID_PATH}=="?*", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", ENV{.BY_BUS}="%c" +ENV{.BY_BUS}=="?*", ENV{.ID_PORT}=="", SYMLINK+="serial/by-bus/%E{.BY_BUS}" +ENV{.BY_BUS}=="?*", ENV{.ID_PORT}=="0", SYMLINK+="serial/by-bus/%E{.BY_BUS}" +ENV{.BY_BUS}=="?*", ENV{.ID_PORT}=="?*", ENV{.ID_PORT}!="0", SYMLINK+="serial/by-bus/%E{.BY_BUS}p%E{.ID_PORT}" LABEL="serial_end" -- cgit v1.2.3