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=mYJDiC+WdicwXqYFsm6HxPrP1ki86e2ImHKgDNQ4EnEzcALszLm6rv7gvWIrNvjL8Luz q8pPcpXzuELuj1GmJ29ijw8m05aoKyVs23b4JThtBZSNKTV1Mytiq+IA25PAZX8h/4l83 6avlwutmAbga5YmpI0IGdE6EvCz+oB6jcDGARlpBoQow1G/xUyyH5Zhz3+87KqakhsDVc D85mm0R+jR3v8iivM+Qeen2vrLngC0n2zxF0Br0Bd6QzFMOuSk/Jw6oWsbNu4to+MfRa6 HYsGoGl3S6ZjYA7AvdawAi4fQBmsmCitMjueUUpn4GwGa56f7cHbmSuw2AiOcDP7ZEQ== 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=cmbgPfNyOypzKZ0EreDGXwIJntyRInukmnFXH5TGAQ3iyCg4J7oL7ZxUtrinoJ6pV8zt 54A364JbwaUM6w/UiZyE7xnfo+jG42y7ve6Nskl4JMcUC3dD2MyCnEBKjSMYGe039JrlU Izttl5vS50NlabUrxeZBLMT94qtt3nuqAvqJT73pCLHEkShbB7HLpzmOfKaUxWIa6yLcc xYr49wSF+1UcKZrZMYKV1l6YrrLE0ya9WcOSkgKimW8M/ROWBHvDrPmRmLAapb8XQE+Xu eLkJTLhGAwhfFhb0k2VTkokBDWQy0AFeYZx3u/YIeOlLFjYNldJehutXgYkfSPPLYDQ== 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 387A5606A31C for ; Sun, 29 Nov 2026 14:02:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 387A5606A31C 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-8b58d6f67a5so4623136b3a.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=1795960936; x=1796565736; 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=mcScrnkwY/z9DY1kIFJyiJLQyBmrWX11mq3bIc6Q0xrLoT/ymLQJNmcAdyasvie5Kv SATwlrUhDGvk9MSHMQfEaMb3kQAYWQ8SD6incbiXHGt6ExiM1hg4woeVRaGkXOT1S+JG 6qvhGjMcwLQ+Nfv/evO2Kx6oPKpTxnVxhwTfUH+XlTzgbBc9U9d8xCz9Aw80+LdEoVLj ic1moSyHYi9uz60UsVYM21J4Slj/SGPEkO5QzrHZHPPFfjbX3Gpyw5HsuVkf4P7gARWY luSe9rkLZUpT+vanWV8kOnSshjbWtAX03lxJO2TMKFE8p7FAOcapi+dZXp5AutUu7b7u AVag== X-Forwarded-Encrypted: i=1; AL+hErFkQ5Sl3z1CtDvLicS9OKkyCofQQmVH9qK3w+T5JZQJWcaQJ01yYOvoaqsV9Dwmfq75RCxtzChT+6L570M=@vger.kernel.org X-Gm-Message-State: APuU4Z+xIAyjctymm0MIK6bjSly4YicOwBDelSIT4ToaZ1UTVI2R7/hd YUFM7fGCEtyg3ckUWjJG8hLdx2XKaXVc4uzt8dY+sYTasfkRzAwb54zv X-Gm-Gg: AZFdTZdI/0CZyaRPYN3YzaFA7ueR92qiGmW7vO716JevS4MOCFX4y+YkdjGQBw+8yc8 daZNwqpzJo+B+OFZB8INIcj6LYg13cHp/bK7v3z/7KVbRVzphiw/xWU8f0f3kVkEDCwkBYjQfsp NPidrFyMQNl5qvpC3aaHDL1Ei2/vUNFAQvDZLbEgd1Me0T+dRYkrfDEGGbrFa7TdUfX8Z9oqvMb VFEou1QyxLJtbop5fHie+vIEgdzE/TeWy2+BJNXqc00cuLyBxdJ6TYwm2GvkpCXSfQr9jUdGJfl DT+jmlY+Q4NDcG0ED0qzn7FRPY6GIMymX4swc9AuxEDVgYP6QkJy84I7qDKzgFis7vrOZ/JGVPC FIUnlP61ExYKvZgMW75qX27NGZkiiMaSEAfRECbs3epT/4025eQWdGfakx+Pt8OIJOvpdlkraE7 zWjZyhNiQxUVxtqVEpddNP9aZIErO0QkKeLN8gonCuh1XDIQFOR8w6yPYS4heuc1KnjIcY+6NUW Skv286j5dtnofQ3qj20Meh9EeN2o+N761Qx9chfCUUn02XcF4Av0MiLkWe1fQtH8mbB/zHxBa6u eV9JrvmOkIsxmdZ6kAX3NV9LVLXpfYJ6v7hZr4TQN2/ArEQZGz9PlcqiyVczZPgQGp0hkuZQ8wb Ln+Snf96sUqmy53TbpfL94sY92hLrsqmpb1Zwb0wNGuExE7W5a4uLJImb1g== 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-kernel@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; }