usb: call usb_packet_cleanup on usb_packet_map failure
PATCH 1/1 usb: call usb_packet_cleanup on usb_packet_map failure
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/usb/hcd-ehci.c | 2 ++ hw/usb/hcd-xhci.c | 1 + 2 files changed, 3 insertions(+)
hw/usb/hcd-ehci.c +2 -0
@@ -1373,6 +1373,7 @@ static int ehci_execute(EHCIPacket *p, const char *action)usb_packet_setup (&p->packet, p->pid, ep,0 , p->qtdaddr, spd, (p->qtd.token &QTD_TOKEN_IOC ) !=0 );if (usb_packet_map (&p->packet, &p->sgl)) { +usb_packet_cleanup (&p->packet);qemu_sglist_destroy (&p->sgl);return -1 ; }
@@ -1456,6 +1457,7 @@ static int ehci_process_itd(EHCIState *ehci,usb_packet_setup (&ehci->ipacket, pid, ep,0 , addr, false, (itd->transact[i] &ITD_XACT_IOC ) !=0 );if (usb_packet_map (&ehci->ipacket, &ehci->isgl)) { +usb_packet_cleanup (&ehci->ipacket);qemu_sglist_destroy (&ehci->isgl);return -1 ; }
hw/usb/hcd-xhci.c +1 -0
@@ -1616,6 +1616,7 @@ static int xhci_setup_packet(XHCITransfer *xfer)usb_packet_setup (&xfer->packet, dir, ep, xfer->streamid, xfer->trbs[0 ].addr, false, xfer->int_req);if (usb_packet_map (&xfer->packet, &xfer->sgl)) { +usb_packet_cleanup (&xfer->packet);qemu_sglist_destroy (&xfer->sgl);return -1 ; }
Signature · 1 line
2.27.0
On 9/1/20 7:27 AM, Gerd Hoffmann wrote:
Reported-by Prasad J Pandit <[email protected]>
Quoted 1 line
Signed-off-by Gerd Hoffmann <[email protected]>
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 38 lines
--- hw/usb/hcd-ehci.c | 2 ++ hw/usb/hcd-xhci.c | 1 + 2 files changed, 3 insertions(+)hw/usb/hcd-ehci.c +2
-0@@ -1373,6 +1373,7 @@ static int ehci_execute(EHCIPacket *p, const char *action)usb_packet_setup (&p->packet, p->pid, ep,0 , p->qtdaddr, spd, (p->qtd.token &QTD_TOKEN_IOC ) !=0 );if (usb_packet_map (&p->packet, &p->sgl)) { +usb_packet_cleanup (&p->packet);qemu_sglist_destroy (&p->sgl);return -1 ; }@@ -1456,6 +1457,7 @@ static int ehci_process_itd(EHCIState *ehci,usb_packet_setup (&ehci->ipacket, pid, ep,0 , addr, false, (itd->transact[i] &ITD_XACT_IOC ) !=0 );if (usb_packet_map (&ehci->ipacket, &ehci->isgl)) { +usb_packet_cleanup (&ehci->ipacket);qemu_sglist_destroy (&ehci->isgl);return -1 ; }hw/usb/hcd-xhci.c +1
-0@@ -1616,6 +1616,7 @@ static int xhci_setup_packet(XHCITransfer *xfer)usb_packet_setup (&xfer->packet, dir, ep, xfer->streamid, xfer->trbs[0 ].addr, false, xfer->int_req);if (usb_packet_map (&xfer->packet, &xfer->sgl)) { +usb_packet_cleanup (&xfer->packet);qemu_sglist_destroy (&xfer->sgl);return -1 ; }
Quoted 12 lines · Gerd Hoffmann <[email protected]> 于2020年9月1日周二 下午1:28写道:
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/usb/hcd-ehci.c | 2 ++ hw/usb/hcd-xhci.c | 1 + 2 files changed, 3 insertions(+)hw/usb/hcd-ehci.c +0
-0
hw/usb/hcd-ehci.c static int ehci_execute(EHCIPacket *p, const char *action) · line 1374
Quoted 2 lines
hw/usb/hcd-ehci.c +0
-0@@ -1373,6 +1373,7 @@ static int ehci_execute(EHCIPacket *p, const char *action)usb_packet_setup (&p->packet, p->pid, ep,0 , p->qtdaddr, spd, (p->qtd.token &QTD_TOKEN_IOC ) !=0 );
Hi Gerd,
’usb_packet_setup‘ doesn't modify the 'iov' and other resources.
'usb_packet_cleanup' is paired with 'usb_packet_init' which I think should be processed in the more up layer.
If 'usb_packet_map' fails, we need to clean the 'iov' in 'usb_packet_map' itself.
Thanks,
Li Qiang
Quoted 29 lines
hw/usb/hcd-ehci.c +2
-0if (usb_packet_map (&p->packet, &p->sgl)) { +usb_packet_cleanup (&p->packet);qemu_sglist_destroy (&p->sgl);return -1 ; }@@ -1456,6 +1457,7 @@ static int ehci_process_itd(EHCIState *ehci,usb_packet_setup (&ehci->ipacket, pid, ep,0 , addr, false, (itd->transact[i] &ITD_XACT_IOC ) !=0 );if (usb_packet_map (&ehci->ipacket, &ehci->isgl)) { +usb_packet_cleanup (&ehci->ipacket);qemu_sglist_destroy (&ehci->isgl);return -1 ; }hw/usb/hcd-xhci.c +1
-1@@ -1616,6 +1616,7 @@ static int xhci_setup_packet(XHCITransfer *xfer)usb_packet_setup (&xfer->packet, dir, ep, xfer->streamid, xfer->trbs[0 ].addr, false, xfer->int_req);if (usb_packet_map (&xfer->packet, &xfer->sgl)) { +usb_packet_cleanup (&xfer->packet);qemu_sglist_destroy (&xfer->sgl);return -1 ; } --2.27.0