hw/usb: Silence compiler warnings in USB code when compiling with -Wshadow
PATCH 1/1 hw/usb: Silence compiler warnings in USB code when compiling with -Wshadow
Rename variables or remove nested definitions where it makes sense, so that we can finally compile the USB code with "-Wshadow", too.
--- hw/usb/desc.c | 2 +- hw/usb/dev-hub.c | 8 ++++---- hw/usb/dev-storage.c | 6 +++--- hw/usb/hcd-xhci.c | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-)
hw/usb/desc.c +1 -1
@@ -227,7 +227,7 @@ int usb_desc_endpoint(const USBDescEndpoint *ep, int flags, }if (superlen) { -USBDescriptor *d = (void *)(dest + bLength); + d = (void *)(dest + bLength); d->bLength =0x06 ; d->bDescriptorType =USB_DT_ENDPOINT_COMPANION ;
hw/usb/dev-hub.c +4 -4
@@ -402,7 +402,7 @@ static void usb_hub_handle_control(USBDevice *dev, USBPacket *p, {unsigned int n = index -1 ;USBHubPort *port; -USBDevice *dev; +USBDevice *pdev;trace_usb_hub_set_port_feature (s->dev.addr, index,feature_name (value));
@@ -411,7 +411,7 @@ static void usb_hub_handle_control(USBDevice *dev, USBPacket *p, goto fail; } port = &s->ports[n]; - dev = port->port.dev; + pdev = port->port.dev;switch (value) {case PORT_SUSPEND : port->wPortStatus |=PORT_STAT_SUSPEND ;
@@ -419,8 +419,8 @@ static void usb_hub_handle_control(USBDevice *dev, USBPacket *p,case PORT_RESET :usb_hub_port_set (port,PORT_STAT_RESET );usb_hub_port_clear (port,PORT_STAT_RESET ); -if (dev && dev->attached) { -usb_device_reset (dev); +if (pdev && pdev->attached) { +usb_device_reset (pdev);usb_hub_port_set (port,PORT_STAT_ENABLE ); }usb_wakeup (s->intr,0 );
hw/usb/dev-storage.c +3 -3
@@ -403,7 +403,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)struct usb_msd_cbw cbw;uint8_t devep = p->ep->nr;SCSIDevice *scsi_dev; -uint32_t len; +int len;if (s->needs_reset) { p->status =USB_RET_STALL ;
@@ -465,7 +465,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)usb_msd_copy_data (s, p); }if (le32_to_cpu (s->csw.residue)) { -int len = p->iov.size - p->actual_length; + len = p->iov.size - p->actual_length;if (len) {usb_packet_skip (p, len);if (len > s->data_len) {
@@ -526,7 +526,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)usb_msd_copy_data (s, p); }if (le32_to_cpu (s->csw.residue)) { -int len = p->iov.size - p->actual_length; + len = p->iov.size - p->actual_length;if (len) {usb_packet_skip (p, len);if (len > s->data_len) {
hw/usb/hcd-xhci.c +5 -5
@@ -217,10 +217,10 @@ enum { (((data) >> field##_SHIFT) & field##_MASK)#define set_field (data, newval, field) do { \ - uint32_t val = *data; \ - val &= ~(field##_MASK << field##_SHIFT); \ - val |= ((newval) & field##_MASK) << field##_SHIFT; \ - *data = val; \ + uint32_t val_ = *data; \ + val_ &= ~(field##_MASK << field##_SHIFT); \ + val_ |= ((newval) & field##_MASK) << field##_SHIFT; \ + *data = val_; \ } while (0) typedef enum EPType {
@@ -1894,7 +1894,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid) }if (epctx->retry) { -XHCITransfer *xfer = epctx->retry; + xfer = epctx->retry;trace_usb_xhci_xfer_retry (xfer);assert (xfer->running_retry);
Signature · 1 line
2.41.0
I got one more:
../hw/usb/host-libusb.c: In function ‘usb_host_open’:../hw/usb/host-libusb.c:1013:13: warning: declaration of ‘rc’ shadows a previous local [-Wshadow=compatible-local]
1013 | int rc = ioctl(hostfd, USBDEVFS_GET_SPEED, NULL);
| ^~../hw/usb/host-libusb.c:954:9: note: shadowed declaration is here
954 | int rc;
| ^~
Quoted 10 lines · Markus Armbruster
I got one more:
../hw/usb/host-libusb.c: In function ‘usb_host_open’:../hw/usb/host-libusb.c:1013:13: warning: declaration of ‘rc’ shadows a previous local [-Wshadow=compatible-local]
1013 | int rc =ioctl(hostfd, USBDEVFS_GET_SPEED, NULL);
| ^~../hw/usb/host-libusb.c:954:9: note: shadowed declaration is here
954 | int rc;
| ^~
Drat, I missed that indeed. I'll send a v2.
Thomas