redo usb_host_find_device() routine - strtoul returning 0 for bus_num
lo list. Trying usb_add host:3.2 was failing with:
/proc/bus/usb/000/002: No such file or directory
in the terminal that qemu was spawned from. It looks like strtoul was
returning 0 for bus_num with the devname "host:3.2". I rewrote the function to use sscanf in both cases.
usb-linux.c +13 -18
@@ -361,28 +377,23 @@static int usb_host_find_device (int *pbus_num,int *paddr,const char *devname) { -const char *p; -int ret;FindDeviceState fs; - p =strchr (devname,'.' ); -if (p) { - *pbus_num =strtoul (devname,NULL ,0 ); - *paddr =strtoul (p +1 ,NULL ,0 ); -return 0 ; - } - p =strchr (devname,':' ); -if (p) { - fs.vendor_id =strtoul (devname,NULL ,16 ); - fs.product_id =strtoul (p +1 ,NULL ,16 ); - ret =usb_host_scan (&fs, usb_host_find_device_scan); -if (ret) { - *pbus_num = fs.bus_num; - *paddr = fs.addr; -return 0 ; +if (sscanf (devname,"host:%03d.%03d" , pbus_num, paddr) !=2 ) { +if (sscanf (devname,"host:%04x:%04x" , &fs.vendor_id, &fs.product_id) ==2 ) { +if (usb_host_scan (&fs, usb_host_find_device_scan)) { + *pbus_num = fs.bus_num; + *paddr = fs.addr; +return 0 ; + }else { +return -1 ; + } + }else { +return -1 ; } + }else { +return 0 ; } -return -1 ; }/**********************/
Quoted 11 lines · Fabrice Bellard
Quoted 7 lines · Lonnie Mendez
lo list. Trying
usb_addhost:3.2 was failing with:
/proc/bus/usb/000/002: No such file or directoryin the terminal that qemu was spawned from. It looks like strtoul was
returning 0 forbus_numwith the devname "host:3.2". I rewrote the function to use sscanf in both cases.Can you confirm ? From the code,
usb_host_find_device()is never called with "host:" as initial string (it is filtered before invl.c).
For whatever reason I am unable to reproduce this now. It may have
been a contaminated binary. For what it's worth this is with a different distro.