summaryrefslogtreecommitdiff
path: root/src/core/device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/device.c')
-rw-r--r--src/core/device.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/core/device.c b/src/core/device.c
index 4f6ecf4d7f..1449867e35 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -55,24 +55,31 @@ static int device_by_path(Manager *m, const char *path, Unit **ret) {
static void device_unset_sysfs(Device *d) {
Hashmap *devices;
- Device *first;
assert(d);
if (!d->sysfs)
return;
- /* Remove this unit from the chain of devices which share the
- * same sysfs path. */
+ /* Remove this unit from the chain of devices which share the same sysfs path. */
+
devices = UNIT(d)->manager->devices_by_sysfs;
- first = hashmap_get(devices, d->sysfs);
- LIST_REMOVE(same_sysfs, first, d);
- if (first)
- hashmap_remove_and_replace(devices, d->sysfs, first->sysfs, first);
+ if (d->same_sysfs_prev)
+ /* If this is not the first unit, then simply remove this unit. */
+ d->same_sysfs_prev->same_sysfs_next = d->same_sysfs_next;
+ else if (d->same_sysfs_next)
+ /* If this is the first unit, replace with the next unit. */
+ assert_se(hashmap_replace(devices, d->same_sysfs_next->sysfs, d->same_sysfs_next) >= 0);
else
+ /* Otherwise, remove the entry. */
hashmap_remove(devices, d->sysfs);
+ if (d->same_sysfs_next)
+ d->same_sysfs_next->same_sysfs_prev = d->same_sysfs_prev;
+
+ d->same_sysfs_prev = d->same_sysfs_next = NULL;
+
d->sysfs = mfree(d->sysfs);
}