diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-09-26 19:03:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 19:03:15 +0200 |
commit | d57e43ad28e6903a6be0ba829d27d8e98ae738fc (patch) | |
tree | 8e81b10a077f005d2ef7e0dc6e3a833c98981232 /src/udev | |
parent | Merge pull request #24808 from medhefgo/fuzz (diff) | |
parent | network: use FOREACH_DEVICE_CHILD_WITH_SUFFIX() macro (diff) | |
download | systemd-d57e43ad28e6903a6be0ba829d27d8e98ae738fc.tar.xz systemd-d57e43ad28e6903a6be0ba829d27d8e98ae738fc.zip |
Merge pull request #24757 from yuwata/sd-device-get-child-first
sd-device: introduce sd_device_get_child_first() and _next()
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/udev-builtin-net_id.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 4acbc87b96..a19bd116ac 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -99,8 +99,8 @@ static sd_device *skip_virtio(sd_device *dev) { static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, char **ret_suffix) { _cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL; - const char *syspath; - _cleanup_closedir_ DIR *dir = NULL; + const char *syspath, *name; + sd_device *child; int r; assert(pcidev); @@ -117,22 +117,15 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha return r; /* Find the virtual function number by finding the right virtfn link. */ - r = device_opendir(physfn_pcidev, NULL, &dir); - if (r < 0) - return r; - - FOREACH_DIRENT_ALL(de, dir, break) { - _cleanup_(sd_device_unrefp) sd_device *virtfn_pcidev = NULL; + FOREACH_DEVICE_CHILD_WITH_SUFFIX(physfn_pcidev, child, name) { const char *n, *s; - n = startswith(de->d_name, "virtfn"); - if (isempty(n)) - continue; - - if (sd_device_new_child(&virtfn_pcidev, physfn_pcidev, de->d_name) < 0) + /* Only accepts e.g. virtfn0, virtfn1, and so on. */ + n = startswith(name, "virtfn"); + if (isempty(n) || !in_charset(n, DIGITS)) continue; - if (sd_device_get_syspath(virtfn_pcidev, &s) < 0) + if (sd_device_get_syspath(child, &s) < 0) continue; if (streq(s, syspath)) { @@ -142,7 +135,7 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha if (!suffix) return -ENOMEM; - *ret_physfn_pcidev = TAKE_PTR(physfn_pcidev); + *ret_physfn_pcidev = sd_device_ref(child); *ret_suffix = suffix; return 0; } |