summaryrefslogtreecommitdiff
path: root/src/udev/udev-builtin-net_id.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-20 11:19:15 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-23 07:03:18 +0900
commit78463c6c4fdcb703bc0dc694c3ea77df3c5624e0 (patch)
treea1428d42d7ca2713645806af1670a2bd544be4f5 /src/udev/udev-builtin-net_id.c
parentfadc8c48acaf2d66c39b75e5ee2020c315e2327f (diff)
downloadsystemd-78463c6c4fdcb703bc0dc694c3ea77df3c5624e0.tar.gz
udev-builtin-net_id: use FOREACH_DEVICE_CHILD_WITH_SUFFIX() macro
Diffstat (limited to 'src/udev/udev-builtin-net_id.c')
-rw-r--r--src/udev/udev-builtin-net_id.c23
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;
}