[PATCH iwinfo 2/4] iwinfo: nl80211: skip ftd and mtd lookups for usb devices
Andre Heider
a.heider at gmail.com
Sun Nov 13 07:11:18 PST 2022
Determine if parent device of the phy belongs to the "usb" subsystem
and skip those expensive lookups accordingly. Those don't even make any
sense for usb devices.
With a 5.15 kernel the mtd lookup even spams dmesg with:
"mtdblock: MTD device 'factory' is NAND, please consider using UBI block
devices instead."
Before:
sys 0m 3.56s$
After:
sys 0m 0.09s
Signed-off-by: Andre Heider <a.heider at gmail.com>
---
iwinfo_nl80211.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index ba92530..fcc48dd 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -3455,7 +3455,8 @@ static int nl80211_hardware_id_from_fdt(struct iwinfo_hardware_id *id, const cha
static int nl80211_get_hardware_id(const char *ifname, char *buf)
{
struct iwinfo_hardware_id *id = (struct iwinfo_hardware_id *)buf;
- char *phy, num[8], path[PATH_MAX];
+ char *phy, *p, num[8], link[PATH_MAX], path[PATH_MAX];
+ bool usb = false;
int i;
struct { const char *path; uint16_t *dest; } lookup[] = {
@@ -3470,6 +3471,16 @@ static int nl80211_get_hardware_id(const char *ifname, char *buf)
/* Try to determine the phy name from the given interface */
phy = nl80211_ifname2phy(ifname);
+ snprintf(path, sizeof(path), "/sys/class/%s/%s/device/subsystem",
+ phy ? "ieee80211" : "net",
+ phy ? phy : ifname);
+
+ if (realpath(path, link)) {
+ p = strrchr(link, '/');
+ if (p)
+ usb = strcmp(p + 1, "usb") == 0;
+ }
+
for (i = 0; i < ARRAY_SIZE(lookup); i++)
{
snprintf(path, sizeof(path), "/sys/class/%s/%s/device/%s",
@@ -3480,14 +3491,16 @@ static int nl80211_get_hardware_id(const char *ifname, char *buf)
*lookup[i].dest = strtoul(num, NULL, 16);
}
- /* Failed to obtain hardware IDs, try FDT */
- if (id->vendor_id == 0 || id->device_id == 0)
- if (!nl80211_hardware_id_from_fdt(id, ifname))
- return 0;
+ if (!usb) {
+ /* Failed to obtain hardware IDs, try FDT */
+ if (id->vendor_id == 0 || id->device_id == 0)
+ if (!nl80211_hardware_id_from_fdt(id, ifname))
+ return 0;
- /* Failed to obtain hardware IDs, search board config */
- if (id->vendor_id == 0 || id->device_id == 0)
- return iwinfo_hardware_id_from_mtd(id);
+ /* Failed to obtain hardware IDs, search board config */
+ if (id->vendor_id == 0 || id->device_id == 0)
+ return iwinfo_hardware_id_from_mtd(id);
+ }
return 0;
}
--
2.35.1
More information about the openwrt-devel
mailing list