Skip to contentSkip to conversation

ALSA: firewire-tascam: Do not drop unread control events

PATCH In review Cássio Gabriel 3 participants 3 messages May 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALSA: firewire-tascam: Do not drop unread control events

tscm_hwdep_read_queue() copies as many queued control events as fit in the userspace buffer. When the buffer is smaller than the current contiguous queue segment, length is rounded down to the number of bytes that can be copied.

However, after copying that shortened length, the code advances pull_pos to the original tail_pos, marking the whole contiguous segment as consumed. Any events between the copied portion and tail_pos are lost.

Limit tail_pos to the position after the entries actually copied before updating pull_pos. When the whole segment fits, this is equivalent to the old tail_pos update; when the buffer is smaller, the remaining events stay queued for the next read.

Fixes a8c0d13267a4 ("ALSA: firewire-tascam: notify events of change of state for userspace applications")

---
Changes in v2:
- Recompute tail_pos after shortening length instead of adding a separate
entries_copied variable, as suggested.
- Add Suggested-by tag.
- Link to v1: https://patch.msgid.link/20260501-alsa-firewire-tascam-read-queue-v1-1-7baa4ba1a4de@gmail.com

---
 sound/firewire/tascam/tascam-hwdep.c | 1 +
 1 file changed, 1 insertion(+)
sound/firewire/tascam/tascam-hwdep.c +1 -0
index 867b4ea1096e..6270263e7bf4 100644
@@ -73,6 +73,7 @@ static long tscm_hwdep_read_queue(struct snd_tscm *tscm, char __user *buf,
 			length = rounddown(remained, sizeof(*entries));
 		if (length == 0)
 			break;
+		tail_pos = head_pos + length / sizeof(*entries);
 
 		spin_unlock_irq(&tscm->lock);
 		if (copy_to_user(pos, &entries[head_pos], length))

---
base-commit: 9e8d6ddd7ecf2ad42d614243f86e50fcf0183b9e
change-id: 20260501-alsa-firewire-tascam-read-queue-7eaef1060adb

Best regards,

Signature · 1 line
Cássio Gabriel <[email protected]>
maintainer Reviewed-by on v2 1/1
#1 lore raw

Hi,

Quoted 24 lines · Cássio Gabriel

tscm_hwdep_read_queue() copies as many queued control events as fit in the userspace buffer. When the buffer is smaller than the current contiguous queue segment, length is rounded down to the number of bytes that can be copied.

However, after copying that shortened length, the code advances pull_pos to the original tail_pos, marking the whole contiguous segment as consumed. Any events between the copied portion and tail_pos are lost.

Limit tail_pos to the position after the entries actually copied before updating pull_pos. When the whole segment fits, this is equivalent to the old tail_pos update; when the buffer is smaller, the remaining events stay queued for the next read.

Fixes a8c0d13267a4 ("ALSA: firewire-tascam: notify events of change of state for userspace applications")

---
Changes in v2:
- Recompute tail_pos after shortening length instead of adding a separate
entries_copied variable, as suggested.
- Add Suggested-by tag.
- Link to v1: https://patch.msgid.link/20260501-alsa-firewire-tascam-read-queue-v1-1-7baa4ba1a4de@gmail.com

Quoted 3 lines
---
 sound/firewire/tascam/tascam-hwdep.c | 1 +
 1 file changed, 1 insertion(+)

Looks good to me;)

Or as a second Co-Author,

To maintainer, please feel free to assign the above tags according to your preferences.

Thanks

Takashi Sakamoto

#2 lore raw
In reply to Cássio Gabriel
Quoted 15 lines · Cássio Gabriel

tscm_hwdep_read_queue() copies as many queued control events as fit in the userspace buffer. When the buffer is smaller than the current contiguous queue segment, length is rounded down to the number of bytes that can be copied.

However, after copying that shortened length, the code advances pull_pos to the original tail_pos, marking the whole contiguous segment as consumed. Any events between the copied portion and tail_pos are lost.

Limit tail_pos to the position after the entries actually copied before updating pull_pos. When the whole segment fits, this is equivalent to the old tail_pos update; when the buffer is smaller, the remaining events stay queued for the next read.

Quoted 4 lines
Fixes a8c0d13267a4 ("ALSA: firewire-tascam: notify events of change of state for userspace applications")

Applied now. Thanks.

Takashi