From mboxrd@z Thu Jan 1 00:00:00 1970 From: George Dunlap Subject: Re: [PATCH v6 2/2] xl: Add commands for usb hot-plug Date: Thu, 25 Apr 2013 11:16:34 +0100 Message-ID: <51790282.8090903@eu.citrix.com> References: <1366387166-21197-1-git-send-email-george.dunlap@eu.citrix.com> <1366387166-21197-2-git-send-email-george.dunlap@eu.citrix.com> <1366807503.20256.333.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1366807503.20256.333.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: "sstanisi@cbnco.com" , Roger Pau Monne , Ian Jackson , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On 04/24/2013 01:45 PM, Ian Campbell wrote: > On Fri, 2013-04-19 at 16:59 +0100, George Dunlap wrote: >> + >> +int main_usb_attach(int argc, char **argv) >> +{ >> + uint32_t domid = INVALID_DOMID; >> + int opt = 0, rc; >> + char *device = NULL; >> + >> + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-attach", 2) { >> + /* No options */ >> + } >> + >> + domid = find_domain(argv[optind]); >> + device = argv[optind + 1]; >> + >> + if (domid == INVALID_DOMID) { >> + fprintf(stderr, "Must specify domid\n\n"); >> + help("usb-attach"); >> + return 2; >> + } > > find_domain won't return in this case, so no need to worry about it > yourself. I find that kind of scary, actually... > >> +int main_usb_detach(int argc, char **argv) >> +{ >> + uint32_t domid = INVALID_DOMID; >> + int opt = 0, rc; >> + char *device = NULL; >> + int type = 0; >> + >> + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-detach", 2) { >> + /* No options */ >> + } >> + >> + domid = find_domain(argv[optind]); >> + device = argv[optind + 1]; >> + >> + if (domid == INVALID_DOMID) { >> + fprintf(stderr, "Must specify domid\n\n"); >> + help("usb-detach"); >> + return 2; >> + } > > > Same again. > >> + >> + rc = usb_detach(domid, type, device); >> + if (rc < 0) >> + return 1; >> + else >> + return 0; >> +} >> + >> +static void usb_list(uint32_t domid) >> +{ >> + libxl_device_usb *dev; >> + int num, i; >> + >> + dev = libxl_device_usb_list(ctx, domid, &num); >> + if (dev == NULL) >> + return; >> + printf("protocol backend type device\n"); >> + for (i = 0; i < num; i++) { >> + printf("%8s ", (dev[i].protocol==LIBXL_USB_PROTOCOL_PV)?"pv":"dm"); > > You can use libxl_usb_protocol_to_string here. Could do, but I didn't necessarily want the long version ("devicemodel"). > >> + printf("%7d ", dev[i].backend_domid); >> + printf("%7s ", (dev[i].type==LIBXL_DEVICE_USB_TYPE_HOSTDEV)?"hostdev":"unknown"); > > libxl_device_usb_type_to_string. Will that print "unknown" in the case of unknown device types? > >> + if (dev[i].type == LIBXL_DEVICE_USB_TYPE_HOSTDEV) >> + printf("%03d.%03d", >> + dev[i].u.hostdev.hostbus, >> + dev[i].u.hostdev.hostaddr); >> + printf("\n"); >> + } >> + free(dev); > > You leak the content of the devices, you need to call > libxl_device_usb_dispose on each, or better define > libxl_device_usb_list_free (this is inconsistently provided by other > devices, but may as well get it right for new code). Ack. -George