On 10/12/15 12:05, George Dunlap wrote: > From: Chunyan Liu > > Add pvusb APIs, including: > - attach/detach (create/destroy) virtual usb controller. > - attach/detach usb device > - list usb controller and usb devices > - some other helper functions > > Signed-off-by: Chunyan Liu > Signed-off-by: Simon Cao > Signed-off-by: George Dunlap Attached is a diff of v9 -> v10 for convenience. One remaining question I had regarding this patch... > +static int usbdev_get_all_interfaces(libxl__gc *gc, const char *busid, > + char ***intfs, int *num) > +{ > + DIR *dir; > + char *buf; > + int rc; > + > + *intfs = NULL; > + *num = 0; > + > + buf = GCSPRINTF("%s:", busid); > + > + dir = opendir(SYSFS_USB_DEV); > + if (!dir) { > + LOGE(ERROR, "opendir failed: '%s'", SYSFS_USB_DEV); > + return ERROR_FAIL; > + } > + > + size_t need = offsetof(struct dirent, d_name) + > + pathconf(SYSFS_USB_DEV, _PC_NAME_MAX) + 1; > + struct dirent *de_buf = libxl__zalloc(gc, need); Is this thing with manually calculating the size of the structure really necessary? Could we not just declare "struct dirent de_buf" on the stack? If it is necessary, it would be better to have it inside a function or macro called "alloc_dirent" or something like that. -George