Skip to content

Commit bc4e2ae

Browse files
btw616jmberg-intel
authored andcommitted
um: vfio: Prevent duplicate device assignments
Ensure devices are assigned only once. Reject subsequent requests for duplicate assignments. Fixes: a0e2cb6 ("um: Add VFIO-based virtual PCI driver") Signed-off-by: Tiwei Bie <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent c55c7a8 commit bc4e2ae

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

arch/um/drivers/vfio_kern.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,17 @@ static void uml_vfio_release_device(struct uml_vfio_device *dev)
570570
kfree(dev);
571571
}
572572

573+
static struct uml_vfio_device *uml_vfio_find_device(const char *device)
574+
{
575+
struct uml_vfio_device *dev;
576+
577+
list_for_each_entry(dev, &uml_vfio_devices, list) {
578+
if (!strcmp(dev->name, device))
579+
return dev;
580+
}
581+
return NULL;
582+
}
583+
573584
static int uml_vfio_cmdline_set(const char *device, const struct kernel_param *kp)
574585
{
575586
struct uml_vfio_device *dev;
@@ -582,6 +593,9 @@ static int uml_vfio_cmdline_set(const char *device, const struct kernel_param *k
582593
uml_vfio_container.fd = fd;
583594
}
584595

596+
if (uml_vfio_find_device(device))
597+
return -EEXIST;
598+
585599
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
586600
if (!dev)
587601
return -ENOMEM;

0 commit comments

Comments
 (0)