diff options
| author | Tiwei Bie <[email protected]> | 2025-06-06 12:44:27 +0000 |
|---|---|---|
| committer | Johannes Berg <[email protected]> | 2025-06-25 07:26:06 +0000 |
| commit | bc4e2ae08183d9017f43bf88aa7cfdf84e76f573 (patch) | |
| tree | 5bf87d6f8c99b4dc4bdaafe3ce88fe32a8d1b4ca | |
| parent | um: ubd: Add missing error check in start_io_thread() (diff) | |
| download | kernel-bc4e2ae08183d9017f43bf88aa7cfdf84e76f573.tar.gz kernel-bc4e2ae08183d9017f43bf88aa7cfdf84e76f573.zip | |
um: vfio: Prevent duplicate device assignments
Ensure devices are assigned only once. Reject subsequent requests
for duplicate assignments.
Fixes: a0e2cb6a9063 ("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]>
| -rw-r--r-- | arch/um/drivers/vfio_kern.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/arch/um/drivers/vfio_kern.c b/arch/um/drivers/vfio_kern.c index b51fc9888ae1..13b971a2bd43 100644 --- a/arch/um/drivers/vfio_kern.c +++ b/arch/um/drivers/vfio_kern.c @@ -570,6 +570,17 @@ static void uml_vfio_release_device(struct uml_vfio_device *dev) kfree(dev); } +static struct uml_vfio_device *uml_vfio_find_device(const char *device) +{ + struct uml_vfio_device *dev; + + list_for_each_entry(dev, ¨_vfio_devices, list) { + if (!strcmp(dev->name, device)) + return dev; + } + return NULL; +} + static int uml_vfio_cmdline_set(const char *device, const struct kernel_param *kp) { struct uml_vfio_device *dev; @@ -582,6 +593,9 @@ static int uml_vfio_cmdline_set(const char *device, const struct kernel_param *k uml_vfio_container.fd = fd; } + if (uml_vfio_find_device(device)) + return -EEXIST; + dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; |
