From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O63cS-0002Av-PJ for qemu-devel@nongnu.org; Sun, 25 Apr 2010 11:19:40 -0400 Received: from [140.186.70.92] (port=49851 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O63cP-0002A4-MO for qemu-devel@nongnu.org; Sun, 25 Apr 2010 11:19:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O63cM-0005RS-3s for qemu-devel@nongnu.org; Sun, 25 Apr 2010 11:19:37 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:58205) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O63cL-0005RH-96 for qemu-devel@nongnu.org; Sun, 25 Apr 2010 11:19:34 -0400 Message-ID: <4BD45D82.1090701@web.de> Date: Sun, 25 Apr 2010 17:19:30 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1272126382-20643-1-git-send-email-daahern@cisco.com> In-Reply-To: <1272126382-20643-1-git-send-email-daahern@cisco.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigFF55A19AA15335E15A7A7103" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH] Changes to usb-linux to conform to coding style List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Ahern Cc: qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFF55A19AA15335E15A7A7103 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable David Ahern wrote: > Signed-off-by: David Ahern Looks good. Picked it up for 'ehci', but this patch should already be considered for upstream as well. Thanks, Jan > --- > usb-linux.c | 374 +++++++++++++++++++++++++++++++++++----------------= -------- > 1 files changed, 224 insertions(+), 150 deletions(-) >=20 > diff --git a/usb-linux.c b/usb-linux.c > index d0d7cff..b3d6b28 100644 > --- a/usb-linux.c > +++ b/usb-linux.c > @@ -105,9 +105,9 @@ enum { > =20 > /* > * Control transfer state. > - * Note that 'buffer' _must_ follow 'req' field because=20 > + * Note that 'buffer' _must_ follow 'req' field because > * we need contigious buffer when we submit control URB. > - */=20 > + */ > struct ctrl_struct { > uint16_t len; > uint16_t offset; > @@ -170,10 +170,10 @@ static void set_halt(USBHostDevice *s, int ep) > s->endp_table[ep - 1].halted =3D 1; > } > =20 > -/*=20 > +/* > * Async URB state. > * We always allocate one isoc descriptor even for bulk transfers > - * to simplify allocation and casts.=20 > + * to simplify allocation and casts. > */ > typedef struct AsyncURB > { > @@ -220,15 +220,16 @@ static void async_complete(void *opaque) > AsyncURB *aurb; > =20 > while (1) { > - USBPacket *p; > + USBPacket *p; > =20 > - int r =3D ioctl(s->fd, USBDEVFS_REAPURBNDELAY, &aurb); > + int r =3D ioctl(s->fd, USBDEVFS_REAPURBNDELAY, &aurb); > if (r < 0) { > - if (errno =3D=3D EAGAIN) > + if (errno =3D=3D EAGAIN) { > return; > - > + } > if (errno =3D=3D ENODEV && !s->closing) { > - printf("husb: device %d.%d disconnected\n", s->bus_num= , s->addr); > + printf("husb: device %d.%d disconnected\n", > + s->bus_num, s->addr); > usb_host_close(s); > usb_host_auto_check(NULL); > return; > @@ -240,21 +241,22 @@ static void async_complete(void *opaque) > =20 > p =3D aurb->packet; > =20 > - DPRINTF("husb: async completed. aurb %p status %d alen %d\n",=20 > + DPRINTF("husb: async completed. aurb %p status %d alen %d\n", > aurb, aurb->urb.status, aurb->urb.actual_length); > =20 > - if (p) { > + if (p) { > switch (aurb->urb.status) { > case 0: > p->len =3D aurb->urb.actual_length; > - if (aurb->urb.type =3D=3D USBDEVFS_URB_TYPE_CONTROL) > + if (aurb->urb.type =3D=3D USBDEVFS_URB_TYPE_CONTROL) {= > async_complete_ctrl(s, p); > + } > break; > =20 > case -EPIPE: > set_halt(s, p->devep); > - p->len =3D USB_RET_STALL; > - break; > + p->len =3D USB_RET_STALL; > + break; > =20 > default: > p->len =3D USB_RET_NAK; > @@ -262,7 +264,7 @@ static void async_complete(void *opaque) > } > =20 > usb_packet_complete(p); > - } > + } > =20 > async_free(aurb); > } > @@ -297,14 +299,15 @@ static int usb_host_claim_interfaces(USBHostDevic= e *dev, int configuration) > =20 > i =3D 0; > dev_descr_len =3D dev->descr[0]; > - if (dev_descr_len > dev->descr_len) > + if (dev_descr_len > dev->descr_len) { > goto fail; > + } > nb_configurations =3D dev->descr[17]; > =20 > i +=3D dev_descr_len; > while (i < dev->descr_len) { > - DPRINTF("husb: i is %d, descr_len is %d, dl %d, dt %d\n", i, d= ev->descr_len, > - dev->descr[i], dev->descr[i+1]); > + DPRINTF("husb: i is %d, descr_len is %d, dl %d, dt %d\n", > + i, dev->descr_len, dev->descr[i], dev->descr[i+1]); > =20 > if (dev->descr[i+1] !=3D USB_DT_CONFIG) { > i +=3D dev->descr[i]; > @@ -312,7 +315,7 @@ static int usb_host_claim_interfaces(USBHostDevice = *dev, int configuration) > } > config_descr_len =3D dev->descr[i]; > =20 > - printf("husb: config #%d need %d\n", dev->descr[i + 5], configuration= );=20 > + printf("husb: config #%d need %d\n", dev->descr[i + 5], config= uration); > =20 > if (configuration < 0 || configuration =3D=3D dev->descr[i + 5= ]) { > configuration =3D dev->descr[i + 5]; > @@ -323,7 +326,8 @@ static int usb_host_claim_interfaces(USBHostDevice = *dev, int configuration) > } > =20 > if (i >=3D dev->descr_len) { > - fprintf(stderr, "husb: update iface failed. no matching config= uration\n"); > + fprintf(stderr, > + "husb: update iface failed. no matching configuration\= n"); > goto fail; > } > nb_interfaces =3D dev->descr[i + 4]; > @@ -416,15 +420,16 @@ static int usb_host_handle_data(USBHostDevice *s,= USBPacket *p) > =20 > urb =3D &aurb->urb; > =20 > - if (p->pid =3D=3D USB_TOKEN_IN) > - urb->endpoint =3D p->devep | 0x80; > - else > - urb->endpoint =3D p->devep; > + if (p->pid =3D=3D USB_TOKEN_IN) { > + urb->endpoint =3D p->devep | 0x80; > + } else { > + urb->endpoint =3D p->devep; > + } > =20 > if (is_halted(s, p->devep)) { > - ret =3D ioctl(s->fd, USBDEVFS_CLEAR_HALT, &urb->endpoint); > + ret =3D ioctl(s->fd, USBDEVFS_CLEAR_HALT, &urb->endpoint); > if (ret < 0) { > - DPRINTF("husb: failed to clear halt. ep 0x%x errno %d\n", = > + DPRINTF("husb: failed to clear halt. ep 0x%x errno %d\n", > urb->endpoint, errno); > return USB_RET_NAK; > } > @@ -449,7 +454,8 @@ static int usb_host_handle_data(USBHostDevice *s, U= SBPacket *p) > =20 > ret =3D ioctl(s->fd, USBDEVFS_SUBMITURB, urb); > =20 > - DPRINTF("husb: data submit. ep 0x%x len %u aurb %p\n", urb->endpoi= nt, p->len, aurb); > + DPRINTF("husb: data submit. ep 0x%x len %u aurb %p\n", > + urb->endpoint, p->len, aurb); > =20 > if (ret < 0) { > DPRINTF("husb: submit failed. errno %d\n", errno); > @@ -470,10 +476,11 @@ static int usb_host_handle_data(USBHostDevice *s,= USBPacket *p) > =20 > static int ctrl_error(void) > { > - if (errno =3D=3D ETIMEDOUT) > + if (errno =3D=3D ETIMEDOUT) { > return USB_RET_NAK; > - else=20 > + } else { > return USB_RET_STALL; > + } > } > =20 > static int usb_host_set_address(USBHostDevice *s, int addr) > @@ -488,12 +495,12 @@ static int usb_host_set_config(USBHostDevice *s, = int config) > usb_host_release_interfaces(s); > =20 > int ret =3D ioctl(s->fd, USBDEVFS_SETCONFIGURATION, &config); > -=20 > + > DPRINTF("husb: ctrl set config %d ret %d errno %d\n", config, ret,= errno); > - =20 > - if (ret < 0) > + > + if (ret < 0) { > return ctrl_error(); > -=20 > + } > usb_host_claim_interfaces(s, config); > return 0; > } > @@ -506,13 +513,13 @@ static int usb_host_set_interface(USBHostDevice *= s, int iface, int alt) > si.interface =3D iface; > si.altsetting =3D alt; > ret =3D ioctl(s->fd, USBDEVFS_SETINTERFACE, &si); > - =20 > - DPRINTF("husb: ctrl set iface %d altset %d ret %d errno %d\n",=20 > - iface, alt, ret, errno); > - =20 > - if (ret < 0) > - return ctrl_error(); > =20 > + DPRINTF("husb: ctrl set iface %d altset %d ret %d errno %d\n", > + iface, alt, ret, errno); > + > + if (ret < 0) { > + return ctrl_error(); > + } > usb_linux_update_endp_table(s); > return 0; > } > @@ -524,7 +531,7 @@ static int usb_host_handle_control(USBHostDevice *s= , USBPacket *p) > int ret, value, index; > int buffer_len; > =20 > - /*=20 > + /* > * Process certain standard device requests. > * These are infrequent and are processed synchronously. > */ > @@ -532,8 +539,8 @@ static int usb_host_handle_control(USBHostDevice *s= , USBPacket *p) > index =3D le16_to_cpu(s->ctrl.req.wIndex); > =20 > DPRINTF("husb: ctrl type 0x%x req 0x%x val 0x%x index %u len %u\n"= , > - s->ctrl.req.bRequestType, s->ctrl.req.bRequest, value, index, = > - s->ctrl.len); > + s->ctrl.req.bRequestType, s->ctrl.req.bRequest, value, ind= ex, > + s->ctrl.len); > =20 > if (s->ctrl.req.bRequestType =3D=3D 0) { > switch (s->ctrl.req.bRequest) { > @@ -546,8 +553,9 @@ static int usb_host_handle_control(USBHostDevice *s= , USBPacket *p) > } > =20 > if (s->ctrl.req.bRequestType =3D=3D 1 && > - s->ctrl.req.bRequest =3D=3D USB_REQ_SET_INTERFACE) > + s->ctrl.req.bRequest =3D=3D USB_REQ_SET_INTERFACE) {= > return usb_host_set_interface(s, index, value); > + } > =20 > /* The rest are asynchronous */ > =20 > @@ -562,12 +570,12 @@ static int usb_host_handle_control(USBHostDevice = *s, USBPacket *p) > aurb->hdev =3D s; > aurb->packet =3D p; > =20 > - /*=20 > + /* > * Setup ctrl transfer. > * > * s->ctrl is layed out such that data buffer immediately follows > * 'req' struct which is exactly what usbdevfs expects. > - */=20 > + */ > urb =3D &aurb->urb; > =20 > urb->type =3D USBDEVFS_URB_TYPE_CONTROL; > @@ -604,9 +612,10 @@ static int do_token_setup(USBDevice *dev, USBPacke= t *p) > USBHostDevice *s =3D (USBHostDevice *) dev; > int ret =3D 0; > =20 > - if (p->len !=3D 8) > + if (p->len !=3D 8) { > return USB_RET_STALL; > -=20 > + } > + > memcpy(&s->ctrl.req, p->data, 8); > s->ctrl.len =3D le16_to_cpu(s->ctrl.req.wLength); > s->ctrl.offset =3D 0; > @@ -614,17 +623,20 @@ static int do_token_setup(USBDevice *dev, USBPack= et *p) > =20 > if (s->ctrl.req.bRequestType & USB_DIR_IN) { > ret =3D usb_host_handle_control(s, p); > - if (ret < 0) > + if (ret < 0) { > return ret; > + } > =20 > - if (ret < s->ctrl.len) > + if (ret < s->ctrl.len) { > s->ctrl.len =3D ret; > + } > s->ctrl.state =3D CTRL_STATE_DATA; > } else { > - if (s->ctrl.len =3D=3D 0) > + if (s->ctrl.len =3D=3D 0) { > s->ctrl.state =3D CTRL_STATE_ACK; > - else > + } else { > s->ctrl.state =3D CTRL_STATE_DATA; > + } > } > =20 > return ret; > @@ -635,16 +647,17 @@ static int do_token_in(USBDevice *dev, USBPacket = *p) > USBHostDevice *s =3D (USBHostDevice *) dev; > int ret =3D 0; > =20 > - if (p->devep !=3D 0) > + if (p->devep !=3D 0) { > return usb_host_handle_data(s, p); > + } > =20 > switch(s->ctrl.state) { > case CTRL_STATE_ACK: > if (!(s->ctrl.req.bRequestType & USB_DIR_IN)) { > ret =3D usb_host_handle_control(s, p); > - if (ret =3D=3D USB_RET_ASYNC) > + if (ret =3D=3D USB_RET_ASYNC) { > return USB_RET_ASYNC; > - > + } > s->ctrl.state =3D CTRL_STATE_IDLE; > return ret > 0 ? 0 : ret; > } > @@ -654,12 +667,14 @@ static int do_token_in(USBDevice *dev, USBPacket = *p) > case CTRL_STATE_DATA: > if (s->ctrl.req.bRequestType & USB_DIR_IN) { > int len =3D s->ctrl.len - s->ctrl.offset; > - if (len > p->len) > + if (len > p->len) { > len =3D p->len; > + } > memcpy(p->data, s->ctrl.buffer + s->ctrl.offset, len); > s->ctrl.offset +=3D len; > - if (s->ctrl.offset >=3D s->ctrl.len) > + if (s->ctrl.offset >=3D s->ctrl.len) { > s->ctrl.state =3D CTRL_STATE_ACK; > + } > return len; > } > =20 > @@ -675,8 +690,9 @@ static int do_token_out(USBDevice *dev, USBPacket *= p) > { > USBHostDevice *s =3D (USBHostDevice *) dev; > =20 > - if (p->devep !=3D 0) > + if (p->devep !=3D 0) { > return usb_host_handle_data(s, p); > + } > =20 > switch(s->ctrl.state) { > case CTRL_STATE_ACK: > @@ -691,12 +707,14 @@ static int do_token_out(USBDevice *dev, USBPacket= *p) > case CTRL_STATE_DATA: > if (!(s->ctrl.req.bRequestType & USB_DIR_IN)) { > int len =3D s->ctrl.len - s->ctrl.offset; > - if (len > p->len) > + if (len > p->len) { > len =3D p->len; > + } > memcpy(s->ctrl.buffer + s->ctrl.offset, p->data, len); > s->ctrl.offset +=3D len; > - if (s->ctrl.offset >=3D s->ctrl.len) > + if (s->ctrl.offset >=3D s->ctrl.len) { > s->ctrl.state =3D CTRL_STATE_ACK; > + } > return len; > } > =20 > @@ -734,8 +752,9 @@ static int usb_host_handle_packet(USBDevice *s, USB= Packet *p) > } > =20 > /* Rest of the PIDs must match our address */ > - if (s->state < USB_STATE_DEFAULT || p->devaddr !=3D s->addr) > + if (s->state < USB_STATE_DEFAULT || p->devaddr !=3D s->addr) { > return USB_RET_NODEV; > + } > =20 > switch (p->pid) { > case USB_TOKEN_SETUP: > @@ -746,7 +765,7 @@ static int usb_host_handle_packet(USBDevice *s, USB= Packet *p) > =20 > case USB_TOKEN_OUT: > return do_token_out(s, p); > -=20 > + > default: > return USB_RET_STALL; > } > @@ -775,8 +794,9 @@ static int usb_linux_update_endp_table(USBHostDevic= e *s) > } > =20 > /* in address state */ > - if (configuration =3D=3D 0) > + if (configuration =3D=3D 0) { > return 1; > + } > =20 > /* get the desired configuration, interface, and endpoint descript= ors > * from device description */ > @@ -822,15 +842,17 @@ static int usb_linux_update_endp_table(USBHostDev= ice *s) > } > =20 > /* advance to the endpoints */ > - while (i < length && descriptors[i +1] !=3D USB_DT_ENDPOINT) > + while (i < length && descriptors[i +1] !=3D USB_DT_ENDPOINT) {= > i +=3D descriptors[i]; > + } > =20 > if (i >=3D length) > break; > =20 > while (i < length) { > - if (descriptors[i + 1] !=3D USB_DT_ENDPOINT) > + if (descriptors[i + 1] !=3D USB_DT_ENDPOINT) { > break; > + } > =20 > devep =3D descriptors[i + 2]; > switch (descriptors[i + 3] & 0x3) { > @@ -866,9 +888,9 @@ static int usb_host_open(USBHostDevice *dev, int bu= s_num, > struct usbdevfs_connectinfo ci; > char buf[1024]; > =20 > - if (dev->fd !=3D -1) > + if (dev->fd !=3D -1) { > goto fail; > - > + } > printf("husb: open device %d.%d\n", bus_num, addr); > =20 > if (!usb_host_device_path) { > @@ -899,21 +921,23 @@ static int usb_host_open(USBHostDevice *dev, int = bus_num, > { > int x; > printf("=3D=3D=3D begin dumping device descriptor data =3D=3D=3D= \n"); > - for (x =3D 0; x < dev->descr_len; x++) > + for (x =3D 0; x < dev->descr_len; x++) { > printf("%02x ", dev->descr[x]); > + } > printf("\n=3D=3D=3D end dumping device descriptor data =3D=3D=3D= \n"); > } > #endif > =20 > =20 > - /*=20 > - * Initial configuration is -1 which makes us claim first=20 > + /* > + * Initial configuration is -1 which makes us claim first > * available config. We used to start with 1, which does not > - * always work. I've seen devices where first config starts=20 > + * always work. I've seen devices where first config starts > * with 2. > */ > - if (!usb_host_claim_interfaces(dev, -1)) > + if (!usb_host_claim_interfaces(dev, -1)) { > goto fail; > + } > =20 > ret =3D ioctl(fd, USBDEVFS_CONNECTINFO, &ci); > if (ret < 0) { > @@ -924,20 +948,23 @@ static int usb_host_open(USBHostDevice *dev, int = bus_num, > printf("husb: grabbed usb device %d.%d\n", bus_num, addr); > =20 > ret =3D usb_linux_update_endp_table(dev); > - if (ret) > + if (ret) { > goto fail; > + } > =20 > - if (ci.slow) > + if (ci.slow) { > dev->dev.speed =3D USB_SPEED_LOW; > - else > + } else { > dev->dev.speed =3D USB_SPEED_HIGH; > + } > =20 > - if (!prod_name || prod_name[0] =3D=3D '\0') > + if (!prod_name || prod_name[0] =3D=3D '\0') { > snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),= > "host:%d.%d", bus_num, addr); > - else > + } else { > pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc), > prod_name); > + } > =20 > /* USB devio uses 'write' flag to check for async completions */ > qemu_set_fd_handler(dev->fd, NULL, async_complete, dev); > @@ -947,15 +974,17 @@ static int usb_host_open(USBHostDevice *dev, int = bus_num, > =20 > fail: > dev->fd =3D -1; > - if (fd !=3D -1) > + if (fd !=3D -1) { > close(fd); > + } > return -1; > } > =20 > static int usb_host_close(USBHostDevice *dev) > { > - if (dev->fd =3D=3D -1) > + if (dev->fd =3D=3D -1) { > return -1; > + } > =20 > qemu_set_fd_handler(dev->fd, NULL, NULL, NULL); > dev->closing =3D 1; > @@ -1012,8 +1041,9 @@ USBDevice *usb_host_device_open(const char *devna= me) > dev =3D usb_create(NULL /* FIXME */, "usb-host"); > =20 > if (strstr(devname, "auto:")) { > - if (parse_filter(devname, &filter) < 0) > + if (parse_filter(devname, &filter) < 0) { > goto fail; > + } > } else { > if ((p =3D strchr(devname, '.'))) { > filter.bus_num =3D strtoul(devname, NULL, 0); > @@ -1049,13 +1079,13 @@ int usb_host_device_close(const char *devname) > int bus_num, addr; > USBHostDevice *s; > =20 > - if (strstr(devname, "auto:")) > + if (strstr(devname, "auto:")) { > return usb_host_auto_del(devname); > - > - if (usb_host_find_device(&bus_num, &addr, product_name, sizeof(pro= duct_name), > - devname) < 0) > + } > + if (usb_host_find_device(&bus_num, &addr, product_name, > + sizeof(product_name), devname) < 0= ) { > return -1; > - > + } > s =3D hostdev_find(bus_num, addr); > if (s) { > usb_device_delete_addr(s->bus_num, s->dev.addr); > @@ -1073,15 +1103,18 @@ static int get_tag_value(char *buf, int buf_siz= e, > const char *p; > char *q; > p =3D strstr(str, tag); > - if (!p) > + if (!p) { > return -1; > + } > p +=3D strlen(tag); > - while (qemu_isspace(*p)) > + while (qemu_isspace(*p)) { > p++; > + } > q =3D buf; > while (*p !=3D '\0' && !strchr(stopchars, *p)) { > - if ((q - buf) < (buf_size - 1)) > + if ((q - buf) < (buf_size - 1)) { > *q++ =3D *p; > + } > p++; > } > *q =3D '\0'; > @@ -1116,51 +1149,62 @@ static int usb_host_scan_dev(void *opaque, USBS= canFunc *func) > device_count =3D 0; > bus_num =3D addr =3D speed =3D class_id =3D product_id =3D vendor_= id =3D 0; > for(;;) { > - if (fgets(line, sizeof(line), f) =3D=3D NULL) > + if (fgets(line, sizeof(line), f) =3D=3D NULL) { > break; > - if (strlen(line) > 0) > + } > + if (strlen(line) > 0) { > line[strlen(line) - 1] =3D '\0'; > + } > if (line[0] =3D=3D 'T' && line[1] =3D=3D ':') { > if (device_count && (vendor_id || product_id)) { > /* New device. Add the previously discovered device. = */ > ret =3D func(opaque, bus_num, addr, class_id, vendor_i= d, > product_id, product_name, speed); > - if (ret) > + if (ret) { > goto the_end; > + } > } > - if (get_tag_value(buf, sizeof(buf), line, "Bus=3D", " ") <= 0) > + if (get_tag_value(buf, sizeof(buf), line, "Bus=3D", " ") <= 0) { > goto fail; > + } > bus_num =3D atoi(buf); > - if (get_tag_value(buf, sizeof(buf), line, "Dev#=3D", " ") = < 0) > + if (get_tag_value(buf, sizeof(buf), line, "Dev#=3D", " ") = < 0) { > goto fail; > + } > addr =3D atoi(buf); > - if (get_tag_value(buf, sizeof(buf), line, "Spd=3D", " ") <= 0) > + if (get_tag_value(buf, sizeof(buf), line, "Spd=3D", " ") <= 0) { > goto fail; > - if (!strcmp(buf, "480")) > + } > + if (!strcmp(buf, "480")) { > speed =3D USB_SPEED_HIGH; > - else if (!strcmp(buf, "1.5")) > + } else if (!strcmp(buf, "1.5")) { > speed =3D USB_SPEED_LOW; > - else > + } else { > speed =3D USB_SPEED_FULL; > + } > product_name[0] =3D '\0'; > class_id =3D 0xff; > device_count++; > product_id =3D 0; > vendor_id =3D 0; > } else if (line[0] =3D=3D 'P' && line[1] =3D=3D ':') { > - if (get_tag_value(buf, sizeof(buf), line, "Vendor=3D", " "= ) < 0) > + if (get_tag_value(buf, sizeof(buf), line, "Vendor=3D", " "= ) < 0) { > goto fail; > + } > vendor_id =3D strtoul(buf, NULL, 16); > - if (get_tag_value(buf, sizeof(buf), line, "ProdID=3D", " "= ) < 0) > + if (get_tag_value(buf, sizeof(buf), line, "ProdID=3D", " "= ) < 0) { > goto fail; > + } > product_id =3D strtoul(buf, NULL, 16); > } else if (line[0] =3D=3D 'S' && line[1] =3D=3D ':') { > - if (get_tag_value(buf, sizeof(buf), line, "Product=3D", ""= ) < 0) > + if (get_tag_value(buf, sizeof(buf), line, "Product=3D", ""= ) < 0) { > goto fail; > + } > pstrcpy(product_name, sizeof(product_name), buf); > } else if (line[0] =3D=3D 'D' && line[1] =3D=3D ':') { > - if (get_tag_value(buf, sizeof(buf), line, "Cls=3D", " (") = < 0) > + if (get_tag_value(buf, sizeof(buf), line, "Cls=3D", " (") = < 0) { > goto fail; > + } > class_id =3D strtoul(buf, NULL, 16); > } > fail: ; > @@ -1171,8 +1215,9 @@ static int usb_host_scan_dev(void *opaque, USBSca= nFunc *func) > product_id, product_name, speed); > } > the_end: > - if (f) > + if (f) { > fclose(f); > + } > return ret; > } > =20 > @@ -1186,7 +1231,8 @@ static int usb_host_scan_dev(void *opaque, USBSca= nFunc *func) > * > * @return 0 failed, 1 succeeded ('line' contains data) > */ > -static int usb_host_read_file(char *line, size_t line_size, const char= *device_file, const char *device_name) > +static int usb_host_read_file(char *line, size_t line_size, > + const char *device_file, const char *dev= ice_name) > { > FILE *f; > int ret =3D 0; > @@ -1228,59 +1274,71 @@ static int usb_host_scan_sys(void *opaque, USBS= canFunc *func) > while ((de =3D readdir(dir))) { > if (de->d_name[0] !=3D '.' && !strchr(de->d_name, ':')) { > char *tmpstr =3D de->d_name; > - if (!strncmp(de->d_name, "usb", 3)) > + if (!strncmp(de->d_name, "usb", 3)) { > tmpstr +=3D 3; > + } > bus_num =3D atoi(tmpstr); > =20 > - if (!usb_host_read_file(line, sizeof(line), "devnum", de->= d_name)) > + if (!usb_host_read_file(line, sizeof(line), "devnum", de->= d_name)) { > goto the_end; > - if (sscanf(line, "%d", &addr) !=3D 1) > + } > + if (sscanf(line, "%d", &addr) !=3D 1) { > goto the_end; > - > + } > if (!usb_host_read_file(line, sizeof(line), "bDeviceClass"= , > - de->d_name)) > + de->d_name)) { > goto the_end; > - if (sscanf(line, "%x", &class_id) !=3D 1) > + } > + if (sscanf(line, "%x", &class_id) !=3D 1) { > goto the_end; > + } > =20 > - if (!usb_host_read_file(line, sizeof(line), "idVendor", de= ->d_name)) > + if (!usb_host_read_file(line, sizeof(line), "idVendor", > + de->d_name)) { > goto the_end; > - if (sscanf(line, "%x", &vendor_id) !=3D 1) > + } > + if (sscanf(line, "%x", &vendor_id) !=3D 1) { > goto the_end; > - > + } > if (!usb_host_read_file(line, sizeof(line), "idProduct", > - de->d_name)) > + de->d_name)) { > goto the_end; > - if (sscanf(line, "%x", &product_id) !=3D 1) > + } > + if (sscanf(line, "%x", &product_id) !=3D 1) { > goto the_end; > - > + } > if (!usb_host_read_file(line, sizeof(line), "product", > de->d_name)) { > *product_name =3D 0; > } else { > - if (strlen(line) > 0) > + if (strlen(line) > 0) { > line[strlen(line) - 1] =3D '\0'; > + } > pstrcpy(product_name, sizeof(product_name), line); > } > =20 > - if (!usb_host_read_file(line, sizeof(line), "speed", de->d= _name)) > + if (!usb_host_read_file(line, sizeof(line), "speed", de->d= _name)) { > goto the_end; > - if (!strcmp(line, "480\n")) > + } > + if (!strcmp(line, "480\n")) { > speed =3D USB_SPEED_HIGH; > - else if (!strcmp(line, "1.5\n")) > + } else if (!strcmp(line, "1.5\n")) { > speed =3D USB_SPEED_LOW; > - else > + } else { > speed =3D USB_SPEED_FULL; > + } > =20 > ret =3D func(opaque, bus_num, addr, class_id, vendor_id, > product_id, product_name, speed); > - if (ret) > + if (ret) { > goto the_end; > + } > } > } > the_end: > - if (dir) > + if (dir) { > closedir(dir); > + } > return ret; > } > =20 > @@ -1329,17 +1387,19 @@ static int usb_host_scan(void *opaque, USBScanF= unc *func) > } > found_devices: > if (!usb_fs_type) { > - if (mon) > + if (mon) { > monitor_printf(mon, "husb: unable to access USB device= s\n"); > + } > return -ENOENT; > } > =20 > /* the module setting (used later for opening devices) */ > usb_host_device_path =3D qemu_mallocz(strlen(devpath)+1); > strcpy(usb_host_device_path, devpath); > - if (mon) > + if (mon) { > monitor_printf(mon, "husb: using %s file-system with %s\n"= , > fs_type[usb_fs_type], usb_host_device_path)= ; > + } > } > =20 > switch (usb_fs_type) { > @@ -1373,27 +1433,29 @@ static int usb_host_auto_scan(void *opaque, int= bus_num, int addr, > QTAILQ_FOREACH(s, &hostdevs, next) { > f =3D &s->match; > =20 > - if (f->bus_num > 0 && f->bus_num !=3D bus_num) > + if (f->bus_num > 0 && f->bus_num !=3D bus_num) { > continue; > - > - if (f->addr > 0 && f->addr !=3D addr) > + } > + if (f->addr > 0 && f->addr !=3D addr) { > continue; > + } > =20 > - if (f->vendor_id > 0 && f->vendor_id !=3D vendor_id) > + if (f->vendor_id > 0 && f->vendor_id !=3D vendor_id) { > continue; > + } > =20 > - if (f->product_id > 0 && f->product_id !=3D product_id) > + if (f->product_id > 0 && f->product_id !=3D product_id) { > continue; > - > + } > /* We got a match */ > =20 > /* Already attached ? */ > - if (s->fd !=3D -1) > + if (s->fd !=3D -1) { > return 0; > - > + } > DPRINTF("husb: auto open: bus_num %d addr %d\n", bus_num, addr= ); > =20 > - usb_host_open(s, bus_num, addr, product_name); > + usb_host_open(s, bus_num, addr, product_name); > } > =20 > return 0; > @@ -1407,21 +1469,24 @@ static void usb_host_auto_check(void *unused) > usb_host_scan(NULL, usb_host_auto_scan); > =20 > QTAILQ_FOREACH(s, &hostdevs, next) { > - if (s->fd =3D=3D -1) > + if (s->fd =3D=3D -1) { > unconnected++; > + } > } > =20 > if (unconnected =3D=3D 0) { > /* nothing to watch */ > - if (usb_auto_timer) > + if (usb_auto_timer) { > qemu_del_timer(usb_auto_timer); > + } > return; > } > =20 > if (!usb_auto_timer) { > usb_auto_timer =3D qemu_new_timer(rt_clock, usb_host_auto_chec= k, NULL); > - if (!usb_auto_timer) > + if (!usb_auto_timer) { > return; > + } > } > qemu_mod_timer(usb_auto_timer, qemu_get_clock(rt_clock) + 2000); > } > @@ -1451,13 +1516,15 @@ static int parse_filter(const char *spec, struc= t USBAutoFilter *f) > f->product_id =3D 0; > =20 > for (i =3D BUS; i < DONE; i++) { > - p =3D strpbrk(p, ":."); > - if (!p) break; > + p =3D strpbrk(p, ":."); > + if (!p) { > + break; > + } > p++; > -=20 > - if (*p =3D=3D '*') > - continue; > =20 > + if (*p =3D=3D '*') { > + continue; > + } > switch(i) { > case BUS: f->bus_num =3D strtol(p, NULL, 10); break; > case DEV: f->addr =3D strtol(p, NULL, 10); break; > @@ -1503,8 +1570,9 @@ static const char *usb_class_str(uint8_t class) > { > const struct usb_class_info *p; > for(p =3D usb_class_info; p->class !=3D -1; p++) { > - if (p->class =3D=3D class) > + if (p->class =3D=3D class) { > break; > + } > } > return p->class_name; > } > @@ -1534,13 +1602,15 @@ static void usb_info_device(Monitor *mon, int b= us_num, int addr, int class_id, > monitor_printf(mon, " Device %d.%d, speed %s Mb/s\n", > bus_num, addr, speed_str); > class_str =3D usb_class_str(class_id); > - if (class_str) > + if (class_str) { > monitor_printf(mon, " %s:", class_str); > - else > + } else { > monitor_printf(mon, " Class %02x:", class_id); > + } > monitor_printf(mon, " USB device %04x:%04x", vendor_id, product_id= ); > - if (product_name[0] !=3D '\0') > + if (product_name[0] !=3D '\0') { > monitor_printf(mon, ", %s", product_name); > + } > monitor_printf(mon, "\n"); > } > =20 > @@ -1559,18 +1629,20 @@ static int usb_host_info_device(void *opaque, i= nt bus_num, int addr, > =20 > static void dec2str(int val, char *str, size_t size) > { > - if (val =3D=3D 0) > + if (val =3D=3D 0) { > snprintf(str, size, "*"); > - else > - snprintf(str, size, "%d", val);=20 > + } else { > + snprintf(str, size, "%d", val); > + } > } > =20 > static void hex2str(int val, char *str, size_t size) > { > - if (val =3D=3D 0) > + if (val =3D=3D 0) { > snprintf(str, size, "*"); > - else > + } else { > snprintf(str, size, "%04x", val); > + } > } > =20 > void usb_host_info(Monitor *mon) > @@ -1580,8 +1652,10 @@ void usb_host_info(Monitor *mon) > =20 > usb_host_scan(mon, usb_host_info_device); > =20 > - if (QTAILQ_EMPTY(&hostdevs)) > + if (QTAILQ_EMPTY(&hostdevs)) { > return; > + } > + > monitor_printf(mon, " Auto filters:\n"); > QTAILQ_FOREACH(s, &hostdevs, next) { > char bus[10], addr[10], vid[10], pid[10]; --------------enigFF55A19AA15335E15A7A7103 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkvUXYIACgkQitSsb3rl5xQMUgCfQ7PJ39bKow0Lk39Rprw0qBeo Qm8An2HBlxWxTYsBB415ds4bAih5Tyg/ =4yKQ -----END PGP SIGNATURE----- --------------enigFF55A19AA15335E15A7A7103--