@@ -138,7 +138,20 @@ static int device_list_add(const char *path,
list_add(&device->dev_list, &fs_devices->devices);
device->fs_devices = fs_devices;
} else if (!device->name || strcmp(device->name, path)) {
- char *name = strdup(path);
+ char *name;
+
+ /*
+ * The existing device has newer generation, so this
+ * one could be a stale one, don't add it.
+ */
+ if (found_transid < device->generation) {
+ warning("adding device %s gen %llu but found an existing device %s gen %llu\n",
+ path, found_transid, device->name,
+ device->generation);
+ return -EEXIST;
+ }
+
+ name = strdup(path);
if (!name)
return -ENOMEM;
kfree(device->name);