* [PATCH] ALSA: serial-generic: remove shared static buffer
@ 2025-09-15 9:42 John Keeping
2025-09-15 10:34 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: John Keeping @ 2025-09-15 9:42 UTC (permalink / raw)
To: linux-sound; +Cc: John Keeping, Jaroslav Kysela, Takashi Iwai, linux-kernel
If multiple instances of this driver are instantiated and try to send
concurrently then the single static buffer snd_serial_generic_tx_work()
will cause corruption in the data output.
Move the buffer into the per-instance driver data to avoid this.
Signed-off-by: John Keeping <jkeeping@inmusicbrands.com>
---
sound/drivers/serial-generic.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/sound/drivers/serial-generic.c b/sound/drivers/serial-generic.c
index 21ae053c05767..766206c6ca75a 100644
--- a/sound/drivers/serial-generic.c
+++ b/sound/drivers/serial-generic.c
@@ -37,6 +37,8 @@ MODULE_LICENSE("GPL");
#define SERIAL_TX_STATE_ACTIVE 1
#define SERIAL_TX_STATE_WAKEUP 2
+#define INTERNAL_BUF_SIZE 256
+
struct snd_serial_generic {
struct serdev_device *serdev;
@@ -51,6 +53,7 @@ struct snd_serial_generic {
struct work_struct tx_work;
unsigned long tx_state;
+ char tx_buf[INTERNAL_BUF_SIZE];
};
static void snd_serial_generic_tx_wakeup(struct snd_serial_generic *drvdata)
@@ -61,11 +64,8 @@ static void snd_serial_generic_tx_wakeup(struct snd_serial_generic *drvdata)
schedule_work(&drvdata->tx_work);
}
-#define INTERNAL_BUF_SIZE 256
-
static void snd_serial_generic_tx_work(struct work_struct *work)
{
- static char buf[INTERNAL_BUF_SIZE];
int num_bytes;
struct snd_serial_generic *drvdata = container_of(work, struct snd_serial_generic,
tx_work);
@@ -78,8 +78,10 @@ static void snd_serial_generic_tx_work(struct work_struct *work)
if (!test_bit(SERIAL_MODE_OUTPUT_OPEN, &drvdata->filemode))
break;
- num_bytes = snd_rawmidi_transmit_peek(substream, buf, INTERNAL_BUF_SIZE);
- num_bytes = serdev_device_write_buf(drvdata->serdev, buf, num_bytes);
+ num_bytes = snd_rawmidi_transmit_peek(substream, drvdata->tx_buf,
+ INTERNAL_BUF_SIZE);
+ num_bytes = serdev_device_write_buf(drvdata->serdev, drvdata->tx_buf,
+ num_bytes);
if (!num_bytes)
break;
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: serial-generic: remove shared static buffer
2025-09-15 9:42 [PATCH] ALSA: serial-generic: remove shared static buffer John Keeping
@ 2025-09-15 10:34 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2025-09-15 10:34 UTC (permalink / raw)
To: John Keeping; +Cc: linux-sound, Jaroslav Kysela, Takashi Iwai, linux-kernel
On Mon, 15 Sep 2025 11:42:19 +0200,
John Keeping wrote:
>
> If multiple instances of this driver are instantiated and try to send
> concurrently then the single static buffer snd_serial_generic_tx_work()
> will cause corruption in the data output.
>
> Move the buffer into the per-instance driver data to avoid this.
>
> Signed-off-by: John Keeping <jkeeping@inmusicbrands.com>
Thanks, applied now to for-next branch.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-15 10:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15 9:42 [PATCH] ALSA: serial-generic: remove shared static buffer John Keeping
2025-09-15 10:34 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox