From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=53808 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PG6cX-0000OL-Ar for qemu-devel@nongnu.org; Wed, 10 Nov 2010 04:05:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PG6cW-0007OS-6s for qemu-devel@nongnu.org; Wed, 10 Nov 2010 04:05:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PG6cV-0007O8-WE for qemu-devel@nongnu.org; Wed, 10 Nov 2010 04:05:32 -0500 From: Hans de Goede Date: Wed, 10 Nov 2010 10:06:24 +0100 Message-Id: <1289379985-12554-3-git-send-email-hdegoede@redhat.com> In-Reply-To: <1289379985-12554-1-git-send-email-hdegoede@redhat.com> References: <1289379985-12554-1-git-send-email-hdegoede@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] usb-linux: introduce a usb_linux_get_configuration function List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: spice-devel@lists.freedesktop.org, Gerd Hoffmann , Hans de Goede The next patch in this series introduces multiple ways to get the configuration dependent upon usb_fs_type, it is cleaner to put this into its own function. --- usb-linux.c | 30 ++++++++++++++++++++++-------- 1 files changed, 22 insertions(+), 8 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 0b154c2..111fe1c 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -775,13 +775,11 @@ static int usb_host_handle_packet(USBDevice *s, USBPacket *p) } } -/* returns 1 on problem encountered or 0 for success */ -static int usb_linux_update_endp_table(USBHostDevice *s) +static int usb_linux_get_configuration(USBHostDevice *s) { - uint8_t *descriptors; - uint8_t devep, type, configuration, alt_interface; + uint8_t configuration; struct usb_ctrltransfer ct; - int interface, ret, length, i; + int ret; ct.bRequestType = USB_DIR_IN; ct.bRequest = USB_REQ_GET_CONFIGURATION; @@ -793,15 +791,31 @@ static int usb_linux_update_endp_table(USBHostDevice *s) ret = ioctl(s->fd, USBDEVFS_CONTROL, &ct); if (ret < 0) { - perror("usb_linux_update_endp_table"); - return 1; + perror("usb_linux_get_configuration"); + return -1; } /* in address state */ if (configuration == 0) { - return 1; + return -1; } + return configuration; +} + +/* returns 1 on problem encountered or 0 for success */ +static int usb_linux_update_endp_table(USBHostDevice *s) +{ + uint8_t *descriptors; + uint8_t devep, type, configuration, alt_interface; + struct usb_ctrltransfer ct; + int interface, ret, length, i; + + i = usb_linux_get_configuration(s); + if (i < 0) + return 1; + configuration = i; + /* get the desired configuration, interface, and endpoint descriptors * from device description */ descriptors = &s->descr[18]; -- 1.7.3.2