From: Hans de Goede <hdegoede@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/8] usb: Add packet combining functions
Date: Thu, 01 Nov 2012 14:59:06 +0100 [thread overview]
Message-ID: <5092802A.7000000@redhat.com> (raw)
In-Reply-To: <50924A2F.7090706@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 573 bytes --]
Hi,
On 11/01/2012 11:08 AM, Gerd Hoffmann wrote:
> On 10/31/12 13:47, Hans de Goede wrote:
>> + /*
>> + * If we had leftover packets the hcd driver will have cancelled them
>> + * and usb_combined_packet_cancel has already freed combined!
>> + */
>> + if (state != leftover) {
>> + g_free(combined);
>> + }
>
> This calls for reference-counting USBCombinedPacket IMHO.
Here is a patch changing the way this is handled to something which
hopefully will be more to your liking. Feel free to squash this
into the original commit.
Regards,
Hans
[-- Attachment #2: 0001-usb-combined-packet-Move-freeing-of-combined-to-usb_.patch --]
[-- Type: text/x-patch, Size: 4087 bytes --]
>From fbcfdf12cbf28c2d1b0e11e290701376aaea554c Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 1 Nov 2012 14:46:31 +0100
Subject: [PATCH] usb/combined-packet: Move freeing of combined to
usb_combined_packet_remove()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/usb/combined-packet.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/hw/usb/combined-packet.c b/hw/usb/combined-packet.c
index e722198..4a0c299 100644
--- a/hw/usb/combined-packet.c
+++ b/hw/usb/combined-packet.c
@@ -31,12 +31,16 @@ static void usb_combined_packet_add(USBCombinedPacket *combined, USBPacket *p)
p->combined = combined;
}
+/* Note will free combined when the last packet gets removed */
static void usb_combined_packet_remove(USBCombinedPacket *combined,
USBPacket *p)
{
assert(p->combined == combined);
p->combined = NULL;
QTAILQ_REMOVE(&combined->packets, p, combined_entry);
+ if (QTAILQ_EMPTY(&combined->packets)) {
+ g_free(combined);
+ }
}
/* Also handles completion of non combined packets for pipelined input eps */
@@ -45,9 +49,8 @@ void usb_combined_input_packet_complete(USBDevice *dev, USBPacket *p)
USBCombinedPacket *combined = p->combined;
USBEndpoint *ep = p->ep;
USBPacket *next;
- enum { completing, complete, leftover };
- int status, actual_length, state = completing;
- bool short_not_ok;
+ int status, actual_length;
+ bool short_not_ok, done = false;
if (combined == NULL) {
usb_packet_complete_one(dev, p);
@@ -61,39 +64,34 @@ void usb_combined_input_packet_complete(USBDevice *dev, USBPacket *p)
short_not_ok = QTAILQ_LAST(&combined->packets, packets_head)->short_not_ok;
QTAILQ_FOREACH_SAFE(p, &combined->packets, combined_entry, next) {
- if (state == completing) {
+ if (!done) {
/* Distribute data over uncombined packets */
if (actual_length >= p->iov.size) {
p->actual_length = p->iov.size;
} else {
/* Send short or error packet to complete the transfer */
p->actual_length = actual_length;
- state = complete;
+ done = true;
}
/* Report status on the last packet */
- if (state == complete || next == NULL) {
+ if (done || next == NULL) {
p->status = status;
} else {
p->status = USB_RET_SUCCESS;
}
p->short_not_ok = short_not_ok;
+ /* Note will free combined when the last packet gets removed! */
usb_combined_packet_remove(combined, p);
usb_packet_complete_one(dev, p);
actual_length -= p->actual_length;
} else {
/* Remove any leftover packets from the queue */
- state = leftover;
p->status = USB_RET_REMOVE_FROM_QUEUE;
+ /* Note will free combined on the last packet! */
dev->port->ops->complete(dev->port, p);
}
}
- /*
- * If we had leftover packets the hcd driver will have cancelled them
- * and usb_combined_packet_cancel has already freed combined!
- */
- if (state != leftover) {
- g_free(combined);
- }
+ /* Do not use combined here, it has been freed! */
leave:
/* Check if there are packets in the queue waiting for our completion */
usb_ep_combine_input_packets(ep);
@@ -104,14 +102,13 @@ void usb_combined_packet_cancel(USBDevice *dev, USBPacket *p)
{
USBCombinedPacket *combined = p->combined;
assert(combined != NULL);
+ USBPacket *first = p->combined->first;
+ /* Note will free combined on the last packet! */
usb_combined_packet_remove(combined, p);
- if (p == combined->first) {
+ if (p == first) {
usb_device_cancel_packet(dev, p);
}
- if (QTAILQ_EMPTY(&combined->packets)) {
- g_free(combined);
- }
}
/*
--
1.7.12.1
next prev parent reply other threads:[~2012-11-01 13:57 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 12:47 [Qemu-devel] usb input pipelining patches v3 Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 1/8] usb: Add packet combining functions Hans de Goede
2012-11-01 10:08 ` Gerd Hoffmann
2012-11-01 13:14 ` Hans de Goede
2012-11-01 13:28 ` Hans de Goede
2012-11-01 13:59 ` Hans de Goede [this message]
2012-11-01 14:23 ` Gerd Hoffmann
2012-11-01 16:17 ` Hans de Goede
2012-11-01 16:42 ` Gerd Hoffmann
2012-11-01 19:07 ` Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 2/8] combined-packet: Add a workaround for Linux usbfs + live migration Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 3/8] usb-redir: Add support for 32 bits bulk packet length Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 4/8] usb-redir: Add support for input pipelining Hans de Goede
2012-11-01 10:10 ` Gerd Hoffmann
2012-11-01 13:16 ` Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 5/8] usb-redir: Add an usbredir_setup_usb_eps() helper function Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 6/8] usb-redir: Use reject rather the disconnect on bad ep info Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 7/8] usb-redir: Allow to attach USB 2.0 devices to 1.1 host controller Hans de Goede
2012-10-31 12:47 ` [Qemu-devel] [PATCH 8/8] usb-redir: Allow redirecting super speed devices to high speed controllers Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5092802A.7000000@redhat.com \
--to=hdegoede@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).