wifi-scripts: find no phy without sysfs or board.json instead of raising

find_phy() raises where /sys/class/ieee80211 is absent: lsdir() returns
null, and the path, macaddr and name lookups index the result. It also
raises where /etc/board.json is absent and the path or name lookup reads
it, because json() rejects the null from readfile().

Take a missing ieee80211 class as no phys, and a missing board.json as no
board data, so that find_phy() returns null or the phy that its path
matches. Every caller already handles null and logs it.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau committed 2026-10-28 14:46:20 +00:00
1 parent 7757608b17
commit cafa893bc0
1 file changed
+8 -3
@@ -58,8 +58,13 @@ function find_phy_by_macaddr(phys, macaddr) {
return filter(phys, (phy) => phy_file(phy, "macaddress") == macaddr)[0];
}
function board_wlan() {
let data = readfile("/etc/board.json");
return data ? json(data).wlan : null;
}
function rename_phy_by_name(phys, name, rename) {
let data = json(readfile("/etc/board.json")).wlan;
let data = board_wlan();
if (!data)
return;
@@ -92,7 +97,7 @@ function find_phy_by_path(phys, path) {
if (!name)
return;
let data = json(readfile("/etc/board.json")).wlan;
let data = board_wlan();
if (!data || data[name])
return name;
@@ -126,7 +131,7 @@ function find_phy_by_name(phys, name, rename) {
}
export function find_phy(config, rename) {
let phys = lsdir("/sys/class/ieee80211");
let phys = lsdir("/sys/class/ieee80211") ?? [];
return find_phy_by_path(phys, config.path) ??
find_phy_by_macaddr(phys, config.macaddr) ??