| @@ -35,6 +35,65 @@ static long tscm_hwdep_read_locked(struct snd_tscm *tscm, char __user *buf, · 34 unmodified lines |
| 35 | return count; | 35 | return count; |
| 36 | } | 36 | } |
| 37 | | 37 | |
| | 38 | static long tscm_hwdep_read_queue(struct snd_tscm *tscm, char __user *buf, |
| | 39 | long remained, loff_t *offset) |
| | 40 | { |
| | 41 | char __user *pos = buf; |
| | 42 | unsigned int type = SNDRV_FIREWIRE_EVENT_TASCAM_CONTROL; |
| | 43 | struct snd_firewire_tascam_change *entries = tscm->queue; |
| | 44 | long count; |
| | 45 | |
| | 46 | // At least, one control event can be copied. |
| | 47 | if (remained < sizeof(type) + sizeof(*entries)) { |
| | 48 | spin_unlock_irq(&tscm->lock); |
| | 49 | return -EINVAL; |
| | 50 | } |
| | 51 | |
| | 52 | // Copy the type field later. |
| | 53 | count = sizeof(type); |
| | 54 | remained -= sizeof(type); |
| | 55 | pos += sizeof(type); |
| | 56 | |
| | 57 | while (true) { |
| | 58 | unsigned int head_pos; |
| | 59 | unsigned int tail_pos; |
| | 60 | unsigned int length; |
| | 61 | |
| | 62 | if (tscm->pull_pos == tscm->push_pos) |
| | 63 | break; |
| | 64 | else if (tscm->pull_pos < tscm->push_pos) |
| | 65 | tail_pos = tscm->push_pos; |
| | 66 | else |
| | 67 | tail_pos = SND_TSCM_QUEUE_COUNT; |
| | 68 | head_pos = tscm->pull_pos; |
| | 69 | |
| | 70 | length = (tail_pos - head_pos) * sizeof(*entries); |
| | 71 | if (remained < length) |
| | 72 | length = rounddown(remained, sizeof(*entries)); |
| | 73 | if (length == 0) |
| | 74 | break; |
| | 75 | |
| | 76 | spin_unlock_irq(&tscm->lock); |
| | 77 | if (copy_to_user(pos, &entries[head_pos], length)) |
| | 78 | return -EFAULT; |
| | 79 | |
| | 80 | spin_lock_irq(&tscm->lock); |
| | 81 | |
| | 82 | tscm->pull_pos = tail_pos % SND_TSCM_QUEUE_COUNT; |
| | 83 | |
| | 84 | count += length; |
| | 85 | remained -= length; |
| | 86 | pos += length; |
| | 87 | } |
| | 88 | |
| | 89 | spin_unlock_irq(&tscm->lock); |
| | 90 | |
| | 91 | if (copy_to_user(buf, &type, sizeof(type))) |
| | 92 | return -EFAULT; |
| | 93 | |
| | 94 | return count; |
| | 95 | } |
| | 96 | |
| 38 | static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, | 97 | static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, |
| 39 | loff_t *offset) | 98 | loff_t *offset) |
| 40 | { | 99 | { |
| @@ -43,7 +102,7 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, · 2 unmodified lines |
| 43 | | 102 | |
| 44 | spin_lock_irq(&tscm->lock); | 103 | spin_lock_irq(&tscm->lock); |
| 45 | | 104 | |
| 46 | while (!tscm->dev_lock_changed) { | 105 | while (!tscm->dev_lock_changed && tscm->push_pos == tscm->pull_pos) { |
| 47 | prepare_to_wait(&tscm->hwdep_wait, &wait, TASK_INTERRUPTIBLE); | 106 | prepare_to_wait(&tscm->hwdep_wait, &wait, TASK_INTERRUPTIBLE); |
| 48 | spin_unlock_irq(&tscm->lock); | 107 | spin_unlock_irq(&tscm->lock); |
| 49 | schedule(); | 108 | schedule(); |
| @@ -56,6 +115,8 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, · 6 unmodified lines |
| 56 | // NOTE: The acquired lock should be released in callee side. | 115 | // NOTE: The acquired lock should be released in callee side. |
| 57 | if (tscm->dev_lock_changed) { | 116 | if (tscm->dev_lock_changed) { |
| 58 | count = tscm_hwdep_read_locked(tscm, buf, count, offset); | 117 | count = tscm_hwdep_read_locked(tscm, buf, count, offset); |
| | 118 | } else if (tscm->push_pos != tscm->pull_pos) { |
| | 119 | count = tscm_hwdep_read_queue(tscm, buf, count, offset); |
| 59 | } else { | 120 | } else { |
| 60 | spin_unlock_irq(&tscm->lock); | 121 | spin_unlock_irq(&tscm->lock); |
| 61 | count = 0; | 122 | count = 0; |
| @@ -73,7 +134,7 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file, · 11 unmodified lines |
| 73 | poll_wait(file, &tscm->hwdep_wait, wait); | 134 | poll_wait(file, &tscm->hwdep_wait, wait); |
| 74 | | 135 | |
| 75 | spin_lock_irq(&tscm->lock); | 136 | spin_lock_irq(&tscm->lock); |
| 76 | if (tscm->dev_lock_changed) | 137 | if (tscm->dev_lock_changed || tscm->push_pos != tscm->pull_pos) |
| 77 | events = EPOLLIN | EPOLLRDNORM; | 138 | events = EPOLLIN | EPOLLRDNORM; |
| 78 | else | 139 | else |
| 79 | events = 0; | 140 | events = 0; |