From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795960936; b=ZPWNKMEeuf/dIONjGy/RMdq+wVPPXvwSQOsBIRXTiWdc/+NEwBLhdvnqKn4Tfymgud7m WujWwCLJc8zrKrJiKrWh0DODTu3e7/Ex4t03hkutRhVVBYWVIfj7Qonbq/QjS4LyM2pqY w8eiB0BY+ALNYjyUtZVKGjXYBKguWW3RDtk/GVIpqPzSv4ivWXRx6Y11HDgWE47Jbfvzm xlrCXSNH6hQtg1/pzue2z53ydxbWs4wYtZvYShSmY47XwLjnc3sTEJe6eCQdv4KZ4LGbn X9TY7xu4vn74Ng3wx7zjKHTvzawoFqr7uLrRjmENGVN6+YwdHghbFec68ud1DTAGhAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795960936; 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=k51dH66pjKg2ARXm5Z55MKmXgfY5v7jgJ4LeomAs8igbflriBOUMII1ckQiuc4z+hZdp kNCRaIGRS5quuYcRRhY4e1+JsKNtCdVyaXZb7D35ZyBYLnQhjmzDrl1epMcQpzNtOBXc1 v1PDPHymWz/O5NeO6VgDbuAO+hjwAoZkkNs/w6nKNLLxCzm9aXeEzSPzDZpNyrtENskq+ Bv9u933EPMaDat/D7WG1V28jnzPab2LqmgGamq9DGGLK4vpnfJRh2+z8PppNiQ9oIiot2 RattY9a8qtidhaoU2LC9u/rPCZkxVvjqFbp7zBrOPSy+pMa5ofZ7hTI7Y2bI2pQMXAQ== 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.173 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 3A2AC606A325 for ; Sun, 29 Nov 2026 14:02:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3A2AC606A325 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-f173.google.com with SMTP id d2e1a72fcca58-8b58d6f67a5so4623135b3a.2 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=adoo3yCmJhn6WI/1ixce4n3xcGVVnadYuQuRploOk1WGp4RE5qmRJ2SNT05ObnrsSG eiTa+Ovjz9MvcuZuSA0DbLOUaOI5SBln8+rCzkdBhsDyBo+PM4PtoEltFTJV229GzoaA IzL+3UyJmla0GW8wAHfx69S2ePClwOyeySwOHX1nAawQr3oQMuaiOs29mPfAbmkeOZOF ypo9+J/iPkGzjHlGYCtPGdvP/2ziO4+VBHWUyj/cBawKBn6QRO9wYxU9I9BtjS3FJEu+ sW9y4aNGLouKPI1aWAlAoilvnzib795C7FvvazF4HinM8kFb5MLTkdviX0ZzvkKHGWdo /2fQ== X-Forwarded-Encrypted: i=1; AL+hErEGkPF/ytifGM6hewy/ed0qrLITi+Sye2j0CsgFWE5LR93bDJu9jQetl18n1t7mTaX+fOXBNTM=@vger.kernel.org X-Gm-Message-State: APuU4Z8pcvG4Q7Nqs2HKlVVz3x+fRXtloPgpSEvtZiVJDPa/bLjeS5J6 U8GEbzBPtcS/Yvx+wFRHtJ4R/W3W0YlJVKYVASZUNaiAZImuO/8dPSZL X-Gm-Gg: AZFdTZe1NfOaBm8PVk7DJftaWjALGVeVi/vled93fpBc//eu5ysUI/Icay4HQ1M8eWa ksM+3a2TNlmF9GlSKjhuSArvRN9dSMC6fdT7tnindIa8+zm+PVmNq1L0D7er5sHNlk62xTMEh6X NXd5nxV7czFq3FxU083hQCFWZUqa/qvTheA/tI0GQ7JKDqS3eAGqF5D/35MGSa9uo+tXft2g2Rl YInEaizm0hJi9CJWc7a9xnWQgsjz7FUgZ5d8e9/79DlYdUZKLywATejonNEIr0wbdV4CzshVlCB B0dhPOZ9r7cCNnUdu/AEiNdO6c/xHJKJSg803IFOgEReQWrOz28gxT6sdyRew5SAnFCaVmuTFWG nHAV9/PqB+0FGmePjVR8UKkoeEcjK9AjdEyetibf0lZ/kUsrbtquIVwrPLvrSvaJM5qBQjnvHAU mn8fxfHB3GRs14dgcAQsN5XYnJUu6PKFK5cnQI2FL1/A9KEz5r7fAPQzbnkMcBZg4PCt8sVk61w 7JihzVqHfAeJExQG3ANnV+O/LV0P/4TvWjq6Zz49WX9aTWLRupRbgMC2DQapOx4sHtCj/KnQnsI 00ax8nNFJuzYwQJ+5JUm+SKmP8ZVQvUkjrejdKMo690+qCUiFMDA269Cx89viI9N4o1Iix2sCgk nM5e/inWmaeJdfrEnpcfQlxRUgEAPmx+DfZSmojr2TK1qiRYTyfGiH6D/qg== 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: stable@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; }