aboutsummaryrefslogtreecommitdiff
path: root/hw/usb/dev-mtp.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-05-28 13:52:03 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-05-28 13:52:03 +0100
commit972b09c219a35b3efffb8a32df943b6c8fbf29ce (patch)
tree9b990f1b150c568785dd1cf75a5ba4f51cb88f65 /hw/usb/dev-mtp.c
parent53651ec26b26440d73ed0f1bcd011e0d636b2d73 (diff)
parent8d1bd3c901a315d0000b09b495fa9d5b87641bd9 (diff)
Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-7' into staging
usb: usb3 streams support for usb-host and usb-redir usb: xhci and mtp bugfixes. # gpg: Signature made Mon 26 May 2014 09:44:09 BST using RSA key ID D3E87138 # gpg: Can't check signature: public key not found * remotes/kraxel/tags/pull-usb-7: usb-host-libusb: Set stream id when submitting bulk-stream transfers usb-host-libusb: Add alloc / free streams ops usb-host-libusb: Fill in endpoint max_streams when available usb-redir: Add support for bulk streams usb-mtp: handle usb_mtp_get_object failure usb-mtp: handle lseek failure usb-mtp: use bool to track MTPObject init status xhci: add xhci_get_flag xhci: add endpoint cap on express bus only xhci: child detach fix Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/usb/dev-mtp.c')
-rw-r--r--hw/usb/dev-mtp.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 943f930404..380b465621 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -46,6 +46,7 @@ enum mtp_code {
/* response codes */
RES_OK = 0x2001,
+ RES_GENERAL_ERROR = 0x2002,
RES_SESSION_NOT_OPEN = 0x2003,
RES_INVALID_TRANSACTION_ID = 0x2004,
RES_OPERATION_NOT_SUPPORTED = 0x2005,
@@ -109,7 +110,8 @@ struct MTPObject {
struct stat stat;
MTPObject *parent;
MTPObject **children;
- int32_t nchildren;
+ uint32_t nchildren;
+ bool have_children;
QTAILQ_ENTRY(MTPObject) next;
};
@@ -273,7 +275,6 @@ static MTPObject *usb_mtp_object_alloc(MTPState *s, uint32_t handle,
o->handle = handle;
o->parent = parent;
o->name = g_strdup(name);
- o->nchildren = -1;
if (parent == NULL) {
o->path = g_strdup(name);
} else {
@@ -340,7 +341,11 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject *o)
struct dirent *entry;
DIR *dir;
- o->nchildren = 0;
+ if (o->have_children) {
+ return;
+ }
+ o->have_children = true;
+
dir = opendir(o->path);
if (!dir) {
return;
@@ -698,7 +703,10 @@ static MTPData *usb_mtp_get_partial_object(MTPState *s, MTPControl *c,
if (offset > o->stat.st_size) {
offset = o->stat.st_size;
}
- lseek(d->fd, offset, SEEK_SET);
+ if (lseek(d->fd, offset, SEEK_SET) < 0) {
+ usb_mtp_data_free(d);
+ return NULL;
+ }
d->length = c->argv[2];
if (d->length > o->stat.st_size - offset) {
@@ -789,9 +797,7 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
c->trans, 0, 0, 0);
return;
}
- if (o->nchildren == -1) {
- usb_mtp_object_readdir(s, o);
- }
+ usb_mtp_object_readdir(s, o);
if (c->code == CMD_GET_NUM_OBJECTS) {
trace_usb_mtp_op_get_num_objects(s->dev.addr, o->handle, o->path);
nres = 1;
@@ -823,7 +829,9 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
}
data_in = usb_mtp_get_object(s, c, o);
if (NULL == data_in) {
- fprintf(stderr, "%s: TODO: handle error\n", __func__);
+ usb_mtp_queue_result(s, RES_GENERAL_ERROR,
+ c->trans, 0, 0, 0);
+ return;
}
break;
case CMD_GET_PARTIAL_OBJECT:
@@ -840,7 +848,9 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
}
data_in = usb_mtp_get_partial_object(s, c, o);
if (NULL == data_in) {
- fprintf(stderr, "%s: TODO: handle error\n", __func__);
+ usb_mtp_queue_result(s, RES_GENERAL_ERROR,
+ c->trans, 0, 0, 0);
+ return;
}
nres = 1;
res0 = data_in->length;