From 4c4e4be4edd5dbf5f7f6a3ef4fc0c243f2d01b3c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 3 Sep 2026 17:08:13 +0200 Subject: ALSA: rawmidi: Add a proper disconnect handling The rawmidi core detaches only exposed devices at disconnection, but it doesn't deal with the pending bytes or gate the further unexpected accesses, leaving naively to each driver dealing with such situations. Let's try to restrict it in the core side for more safety: introduce the disconnected flag to each substream, set it at disconnection call, then trigger down & cancel the pending event work. Link: https://patch.msgid.link/20260903150816.1917831-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- include/sound/rawmidi.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h index 4154035af414..d812f70725bd 100644 --- a/include/sound/rawmidi.h +++ b/include/sound/rawmidi.h @@ -86,6 +86,7 @@ struct snd_rawmidi_substream { bool opened; /* open flag */ bool append; /* append flag (merge more streams) */ bool active_sensing; /* send active sensing when close */ + bool disconnected; /* already disconnected */ unsigned int framing; /* whether to frame input data */ unsigned int clock_type; /* clock source to use for input framing */ int use_count; /* use counter (for output) */ -- cgit v1.2.3