From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795960937; b=PSAIPjGRc1DPqcGUS8dpypr8oNjsbFvaEy/9VOXpDAJw4LWk0JW5fFZQs+fSb1PY2SuF RsG3eQZbYtODpc1dloIKuuirlVTWbOnTsVY608UF4upgufaYmkUqwBSq69CNLyj5b8sq2 tTdPun5jKck/3ruVxHuClGZnlqLNHRpxitPyXXlCGE+NWr0lDmiZYDkAYTRq80xGzQ30Y 4Hv39V6Fu9nHVAOtt9cEXM9riQRqDPgTnnbQkPotXEs2keO9dGtZAYo9uLJdYTjnVVpJ9 6kPfH8ZBvpwTyeZ7keZAnDpF43riT4D7MrGTiF6hPDTvtLqDPeCeGhwlNqBSikIcQVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795960937; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=EZNhgxwffYYcjAbHMjoWxWrQXq5cF6pcLzXRo9RSGdA=; b=Pn1jJ4exgvyLyYdHXtHws1/G/7b7UPl1aPFSSvqZX4LSWYrfv90hEetIYJqfjinVm3eH ptAupKXAFt8MbLH15SM74TcHFTuonWSUGpRejyYNBRBUmdGoN1V/jGEtK2jhjUvYlUYNN bGjvDUpgI8Gt92tN9XCYGtAwJJrRIn/eauCbOmA/OyNcWfPIktAf144pnW1YVNhAyix2B YX3SWrvBTZ5+QhLX63CuAphqonJQOPGg4kTvnQX6x2t8FKyNbiza22F4F1sDi3/aGKQuC QsXmMMmMHmax5J2H/f1Y6kWL+FKM2HAGsvV2hCeL9MTmx2R3BkgdM4R8ugBIUc7hyRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=de+piYhC; arc=none smtp.remote-ip=209.85.210.174 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3887A606A323 for ; Sun, 29 Nov 2026 14:02:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3887A606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=de+piYhC Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-8b904d10882so3919642b3a.0 for ; Sun, 29 Nov 2026 06:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795960935; x=1796565735; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=EZNhgxwffYYcjAbHMjoWxWrQXq5cF6pcLzXRo9RSGdA=; b=de+piYhC2ln7x2DXEawhhfKw4tUEraD+esKJ+eeOzH/nZ5PAuOjZGdJKk6Y/DJ4fTo 6kTIR+u0OKN6Fqak6J2MwE99gtKt/bUGvt3/tXvvZNnB0flPknJd4W2laFnjS8WKsNjH 718M6aG4Hlk1++Ky1nJLU39oKUW4LgXBvYARtN+jzXr00KOjc7S7KlA1TmC5Xbmr5ANJ ygljfNsOouudyhq6SEhuCpG9fTt9d5zodkfqBBZXxHHfEArBnWO7rZHJwhELXdc/BEFD HC50fn63CJ/SxtOUbNl+JJrx4OFm/vftcGS7KtPPIjmeYDKNWBTeHeqOLNDe5E9DXL3g c5MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795960935; x=1796565735; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EZNhgxwffYYcjAbHMjoWxWrQXq5cF6pcLzXRo9RSGdA=; b=IFzi0u9ip2BRjOQn20amZUAWrBh1GRv87lXvGlq6sND7TENaO4jchykEEsxyrJOmLL UGUeYITVK0pjhZjvAih2Q43CwprFXa+EgSBrycliNuHJ2h1yM0zWxBA06a3Kya4947rr 90muEyjZ07znm/nAeanm7RUiTZuEsOdAtFXZM+3Vg0XGGmFYAwWuvL+oLMmVvpRc5ADZ U5I4HfP7sPYuwu36uTa6lDj8zzQb6K6sgPLOfsL/E0nBnk3Oy8yiJ47WMSrqHf1L1jU1 nBzgIEvztlnPytXqFbG10H1+xSm9mvzM8QnmTsd/x2Oxvl7bGj4ySeYfIBBBMtKdSVWb KzqA== X-Forwarded-Encrypted: i=1; AL+hErG77f82ZqJ5c3FHLXm5xBnB4fPEVWw7RTUEwh+MClMC/SgLWubrFuCYZYK0zn1eB57AKOwvKE285h0=@vger.kernel.org X-Gm-Message-State: APuU4Z+Rem+tgLSLRJhpes+gNc33y3Wvg7XZ6VLhQYnuF31E5vlV//AN HgqrHc3NtaYZDLZIh3EKJv8J74w+pEhmQ2HK5YlYPmcClSnAf8D3/iQc X-Gm-Gg: AZFdTZf9nIWb8cUk8v573U1JCi21PKUkr7pBWTmYzMMQbukiSTNDiDipuv3RsBTqG/u 7y3s0DFs3FbLYtTcHTJU149sQ4dcntYTPKOfbbH1DDurCFfqtnt1b5/TkT8Vi38ZCnEFhZgrlCM aSQHfMwp9aGak3DB2KpwRFGUw4hLmWylV2uoLDk9KiRF21Vma99BhSrsLTfn1xilul77kUNufsp S2Nv2zSePG9A3odseJkJfWRs4zfgYawAEbsQ1giHq5U0PYpDYO/CBo/k8iSeyvSsHaIlMjVx+Rf n/RFTWXodyzZlMi0KRNZMTQSLrcdozDezcFqvcoiy3tyVeeuYIxUYakGIWPug/BI9yX0Kn+awXx rSVQsCSkgNUQa249n3CgXjj4LwFYnpzecohWFHu7zwU2Bn7vhOqyl6swEVH6kXFNhXcJR+AEk2i Ux7UHEfY9ZA2qvGKLCtoW6l+9edBowJ5T/QgR+soJwFs1GADAC36lJ/gY4s7OByTqcQmLYTTZWQ 0cv5wQdUWAu9rp4L8NNojwWU336SZUm4HssnDQoozgDFmE/KWgdkLsPxMO2au6vJF9TnvXEDeNN Im93x+/+GeBoUMZt+TJYKXjOQqirq94z1d9DicLCPczVvk1RYabXNNZlBRjZZqEb3etgDjF/x0a QJpQSpDn6NGSjISbzYgRB1aaH6DvuPg5YDcFuPSdPgjF6UZGR19CnxI/Dow== X-Received: by 2002:a05:6a00:94fb:b0:891:3049:8ef8 with SMTP id d2e1a72fcca58-8c87d5169c8mr27024703b3a.47.1795960935439; Sun, 29 Nov 2026 06:02:15 -0800 (PST) Received: from ssslab.. (ssslab.skku.edu. [115.145.172.159]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c872e456a7sm15946274b3a.29.2026.11.29.06.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 06:02:15 -0800 (PST) From: Jaegyun Lee To: Greg Kroah-Hartman , Neill Kapron Cc: Jaegyun Lee , Takashi Iwai , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] usb: gadget: midi2: do not repeat a MIDI 1.0 message at a request boundary Date: Sun, 29 Nov 2026 23:02:09 +0900 Message-Id: <20261129140209.547953-1-dreams200260@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In MIDI 1.0 mode (altset 0) process_midi1_transmit() converts UMP data from user space into USB-MIDI 1.0 packets through a per-cable byte buffer (midi2->midi1_port[cable].buf/pending). process_midi1_byte() returns true when the packet it just wrote filled the USB request (req_buf_size - length <= 4) and the request was queued: memcpy(req->buf + req->length, p, sizeof(p)); req->length += sizeof(p); ... if (midi2->info.req_buf_size - req->length <= 4) { queue_request_ep_raw(req); *req_p = NULL; return true; } and process_midi1_pending_buf() then keeps byte c at the head of the buffer: if (process_midi1_byte(midi2, cable, port->buf[c], req_p)) { port->pending -= c; if (port->pending) memmove(port->buf, port->buf + c, port->pending); return true; } Byte c has already been turned into a packet, but it is kept at the head of the buffer and the running-status state is not advanced, so on the next pass it is converted again with the same state: the last MIDI 1.0 message of every full request (127 packets = 508 bytes) is sent twice. Reproduced by having the gadget write 1000 distinct MIDI 1.0 note-on UMPs to /dev/snd/umpCD0 while the host reads the MIDI 1.0 IN endpoint: host /dev/bus/usb/001/002, gadget /dev/snd/umpC3D0, MIDI 1.0 IN ep 0x81, sending 1000 note-ons DUPLICATE note-on #126 (note 126 vel 1) = packet 127, byte offset 508 of the stream DUPLICATE note-on #252 (note 124 vel 2) = packet 254, byte offset 1016 of the stream DUPLICATE note-on #382 (note 126 vel 3) = packet 385, byte offset 1540 of the stream DUPLICATE note-on #508 (note 124 vel 4) = packet 512, byte offset 2048 of the stream DUPLICATE note-on #638 (note 126 vel 5) = packet 643, byte offset 2572 of the stream DUPLICATE note-on #764 (note 124 vel 6) = packet 770, byte offset 3080 of the stream DUPLICATE note-on #894 (note 126 vel 7) = packet 901, byte offset 3604 of the stream RESULT sent=1000 received_packets=1007 note_on=1007 in_order=1000 duplicates=7 other=0 transfers=11 Advance the state and drop byte c too when the request is full. Fixes: d6468be779af ("usb: gadget: midi2: MIDI 1.0 interface (altset 0) support") Cc: stable@vger.kernel.org Assisted-by: ZCode:GLM-5.4 Signed-off-by: Jaegyun Lee --- drivers/usb/gadget/function/f_midi2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_midi2.c b/drivers/usb/gadget/function/f_midi2.c --- a/drivers/usb/gadget/function/f_midi2.c +++ b/drivers/usb/gadget/function/f_midi2.c @@ -925,6 +925,7 @@ static bool process_midi1_byte(struct f_ } if (midi2->info.req_buf_size - req->length <= 4) { + port->state = next_state; queue_request_ep_raw(req); *req_p = NULL; return true; @@ -952,9 +953,9 @@ static bool process_midi1_pending_buf(st for (c = 0; c < port->pending; c++) { if (process_midi1_byte(midi2, cable, port->buf[c], req_p)) { - port->pending -= c; + port->pending -= c + 1; if (port->pending) - memmove(port->buf, port->buf + c, + memmove(port->buf, port->buf + c + 1, port->pending); return true; }