From cca35636023c3b814c497773405f762eb7d63163 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 10 Jun 2025 14:31:20 +0200 Subject: [PATCH] virt-aa-helper: Rework USB hostdev handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For an USB device, the virt-aa-helper must put that /dev/bus/usb/... path associated with given device. The way the code is currently written not only leads to a memleak (the @usb variable is allocated only to be overwritten right away), but is needlessly cumbersome. We can use virHostdevFindUSBDevice() to find the USB device, check if its missing and if not add the path associated with it into the profile. While at it, also use automatic memory freeing for the variable. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- src/security/virt-aa-helper.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index d4358ebf9c..a56d7e9062 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1040,24 +1040,21 @@ get_files(vahControl * ctl) for (i = 0; i < ctl->def->nhostdevs; i++) if (ctl->def->hostdevs[i]) { virDomainHostdevDef *dev = ctl->def->hostdevs[i]; - virDomainHostdevSubsysUSB *usbsrc = &dev->source.subsys.u.usb; if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevice *usb = - virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL); + g_autoptr(virUSBDevice) usb = NULL; - if (usb == NULL) + if (virHostdevFindUSBDevice(dev, true, &usb) < 0) continue; - if (virHostdevFindUSBDevice(dev, true, &usb) < 0) + if (dev->missing) continue; rc = virUSBDeviceFileIterate(usb, file_iterate_hostdev_cb, &buf); - virUSBDeviceFree(usb); if (rc != 0) goto cleanup; break; -- 2.47.3