Minor USB cleanups
cover Minor USB cleanups
Markus Armbruster (3):
ehci: Assert state machine is sane w.r.t. EHCIQueue
usb-host: Drop superfluous null test from usb_host_auto_scan()
usb-host: Initialize dev->port the obviously safe way
hw/usb/hcd-ehci.c | 4 ++++ hw/usb/host-linux.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/3 ehci: Assert state machine is sane w.r.t. EHCIQueue
Coverity worries the EHCIQueue pointer could be null when we pass it to functions that reference it. The state machine ensures it can't be null then. Assert that, to hush the checker.
--- hw/usb/hcd-ehci.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/usb/hcd-ehci.c +4 -0
@@ -2092,18 +2092,22 @@ static void ehci_advance_state(EHCIState *ehci, int async)break ;case EST_ADVANCEQUEUE : +assert (q !=NULL ); again =ehci_state_advqueue (q);break ;case EST_FETCHQTD : +assert (q !=NULL ); again =ehci_state_fetchqtd (q);break ;case EST_HORIZONTALQH : +assert (q !=NULL ); again =ehci_state_horizqh (q);break ;case EST_EXECUTE : +assert (q !=NULL ); again =ehci_state_execute (q);if (async) { ehci->async_stepdown =0 ;
Signature · 1 line
1.7.11.7
PATCH 2/3 usb-host: Drop superfluous null test from usb_host_auto_scan()
In reply to Markus ArmbrusterCoverity points out that port is later passed to usb_host_open(), which dereferences it. It actually can't be null: it always points to usb_host_scan()'s auto port[]. Drop the superfluous port == NULL test.
--- hw/usb/host-linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/host-linux.c +1 -1
@@ -1760,7 +1760,7 @@ static int usb_host_auto_scan(void *opaque, int bus_num,if (f->addr >0 && f->addr != addr) {continue ; } -if (f->port !=NULL && (port ==NULL ||strcmp (f->port, port) !=0 )) { +if (f->port !=NULL &&strcmp (f->port, port) !=0 ) {continue ; }
Signature · 1 line
1.7.11.7
PATCH 3/3 usb-host: Initialize dev->port the obviously safe way
In reply to Markus ArmbrusterCoverity worries the strcpy() could overrun the destination. It can't, because the source always points to usb_host_scan()'s auto port[], which has the same size. Use pstrcpy() anyway, to hush the checker.
--- hw/usb/host-linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/host-linux.c +1 -1
@@ -1314,7 +1314,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num, dev->bus_num = bus_num; dev->addr = addr; -strcpy (dev->port, port); +pstrcpy (dev->port,sizeof (dev->port), port); dev->fd = fd;/* read the device description */
Signature · 1 line
1.7.11.7
Quoted 9 lines · Markus Armbruster
Markus Armbruster (3):
ehci: Assert state machine is sane w.r.t. EHCIQueue
usb-host: Drop superfluous null test fromusb_host_auto_scan()
usb-host: Initializedev->portthe obviously safe wayhw/usb/hcd-ehci.c | 4 ++++ hw/usb/host-linux.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-)
Patch added to usb patch queue.
thanks,
Gerd