From ee804a84fadc46c5a6b683cd0f96b2299f4377a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Thu, 26 May 2016 11:46:49 +0200 Subject: [PATCH] usb: do not allocate raw packets without size Allocating a packet in the packet stream without a payload is not allowed. Therefore we have to allocate CTRL message packets, that do not have a payload, with a bogus length instead. --- repos/libports/src/lib/qemu-usb/host.cc | 11 ++++++++++- repos/os/include/usb/packet_handler.h | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/repos/libports/src/lib/qemu-usb/host.cc b/repos/libports/src/lib/qemu-usb/host.cc index 6255b6b73..0083f9c5c 100644 --- a/repos/libports/src/lib/qemu-usb/host.cc +++ b/repos/libports/src/lib/qemu-usb/host.cc @@ -228,10 +228,19 @@ struct Usb_host_device : List::Element Usb::Packet_descriptor alloc_packet(int length) { - if (!usb_raw.source()->ready_to_submit()) throw -1; + if (length <= 0) { + /* + * XXX Packets without payload are not supported by the packet stream + * currently. Therefore, we use a (small) bogus length + * here and depend on the USB driver to handle this case + * correctly. + */ + length = 4; + } + Usb::Packet_descriptor packet = usb_raw.source()->alloc_packet(length); packet.completion = alloc_completion(); return packet; diff --git a/repos/os/include/usb/packet_handler.h b/repos/os/include/usb/packet_handler.h index f739f0886..2ad6ee637 100644 --- a/repos/os/include/usb/packet_handler.h +++ b/repos/os/include/usb/packet_handler.h @@ -85,6 +85,16 @@ class Usb::Packet_handler throw Usb::Session::Tx::Source::Packet_alloc_failed(); } + if (size == 0) { + /* + * XXX Packets without payload are not supported by the packet + * stream currently. Therefore, we use a (small) bogus + * length here and depend on the USB driver to handle this + * case correctly. + */ + size = 4; + } + while (true) { try { Packet_descriptor p = _connection.source()->alloc_packet(size);