Commit fe2a7966db for qemu.org

commit fe2a7966db94e9ed37a0dc4b40ad79a0e6041ecc
Author: Tommaso Califano <tcalifano@redhat.com>
Date:   Thu Nov 12 18:49:06 2026 +0100

    hw/usb/dev-mtp: Stop processing SendObjectInfo after an error

    When SendObjectInfo fails its checks, usb_mtp_command() queues an error
    response and then falls through. It still allocates s->data_out. The
    data phase is then dropped because a result is pending, so s->data_out
    is never released.

    Return right after queueing the error response.

    Cc: qemu-stable@nongnu.org
    Fixes: 53735bef108c ("usb-mtp: Advertise SendObjectInfo for write support")
    Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4529
    Suggested-by: Hui Peng <https://gitlab.com/benquike>
    Signed-off-by: Tommaso Califano <tcalifano@redhat.com>
    Reviewed-by: Junjie Cao <junjie.cao@linux.dev>
    Tested-by: Junjie Cao <junjie.cao@linux.dev>
    Message-ID: <20261112174907.158825-10-tcalifano@redhat.com>
    Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 92dc9a9e21..a8b89c938b 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1393,14 +1393,17 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
         if (!FLAG_SET(s, MTP_FLAG_WRITABLE)) {
             usb_mtp_queue_result(s, RES_STORE_READ_ONLY,
                                  c->trans, 0, 0, 0, 0);
+            return;
         } else if (c->argv[0] && (c->argv[0] != QEMU_STORAGE_ID)) {
             /* First parameter points to storage id or is 0 */
             usb_mtp_queue_result(s, RES_STORE_NOT_AVAILABLE, c->trans,
                                  0, 0, 0, 0);
+            return;
         } else if (c->argv[1] && !c->argv[0]) {
             /* If second parameter is specified, first must also be specified */
             usb_mtp_queue_result(s, RES_DESTINATION_UNSUPPORTED, c->trans,
                                  0, 0, 0, 0);
+            return;
         } else {
             uint32_t handle = c->argv[1];
             if (handle == 0xFFFFFFFF || handle == 0) {
@@ -1412,9 +1415,11 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
             if (o == NULL) {
                 usb_mtp_queue_result(s, RES_INVALID_OBJECT_HANDLE, c->trans,
                                      0, 0, 0, 0);
+                return;
             } else if (o->format != FMT_ASSOCIATION) {
                 usb_mtp_queue_result(s, RES_INVALID_PARENT_OBJECT, c->trans,
                                      0, 0, 0, 0);
+                return;
             }
         }
         if (o) {