diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-10-21 16:34:20 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-10-21 16:34:20 +0000 |
commit | f16a0db323e1a8c0044696815cceeb98706f2243 (patch) | |
tree | 19e50daf4aea551fae0e4c87438a8791537e450a /usb-linux.c | |
parent | a2ffb81204ccfb497908773729f8d2f1048a65c4 (diff) |
Keep usb host scanning from leaking file descriptors
If the first case does not succeed, then the usb scanning code will leak file
descriptors on every scan.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5509 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'usb-linux.c')
-rw-r--r-- | usb-linux.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/usb-linux.c b/usb-linux.c index 7e94c6aa3d..a8dd897f20 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1276,27 +1276,31 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) usb_fs_type = USB_FS_PROC; fclose(f); dprintf(opened, USBPROCBUS_PATH, devices); + goto found_devices; } /* try additional methods if an access method hasn't been found yet */ f = fopen(USBDEVBUS_PATH "/devices", "r"); - if (!usb_fs_type && f) { + if (f) { /* devices found in /dev/bus/usb/ */ strcpy(devpath, USBDEVBUS_PATH); usb_fs_type = USB_FS_DEV; fclose(f); dprintf(opened, USBDEVBUS_PATH, devices); + goto found_devices; } dir = opendir(USBSYSBUS_PATH "/devices"); - if (!usb_fs_type && dir) { + if (dir) { /* devices found in /dev/bus/usb/ (yes - not a mistake!) */ strcpy(devpath, USBDEVBUS_PATH); usb_fs_type = USB_FS_SYS; closedir(dir); dprintf(opened, USBSYSBUS_PATH, devices); + goto found_devices; } + found_devices: if (!usb_fs_type) { term_printf("husb: unable to access USB devices\n"); - goto the_end; + return -ENOENT; } /* the module setting (used later for opening devices) */ @@ -1307,7 +1311,7 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) } else { /* out of memory? */ perror("husb: unable to allocate memory for device path"); - goto the_end; + return -ENOMEM; } } @@ -1319,8 +1323,10 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) case USB_FS_SYS: ret = usb_host_scan_sys(opaque, func); break; + default: + ret = -EINVAL; + break; } - the_end: return ret; } |