ALSA: firewire-tascam: apply small refactoring to handle several type of event for...
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 23 Nov 2018 04:13:06 +0000 (13:13 +0900)
committerTakashi Iwai <tiwai@suse.de>
Fri, 23 Nov 2018 14:31:14 +0000 (15:31 +0100)
In later commits, ALSA firewire-tascam driver will allow userspace
applications to receive notifications about changes of device state,
transferred in tx isochronous packet. At present, all of drivers in ALSA
firewire stack have mechanism to notify change of status of packet
streaming, thus it needs to distinguish these two types of notification.

This commit is a preparation for the above.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/tascam/tascam-hwdep.c

index 9afa827..8f34ced 100644 (file)
 
 #include "tascam.h"
 
+static long tscm_hwdep_read_locked(struct snd_tscm *tscm, char __user *buf,
+                                  long count, loff_t *offset)
+{
+       struct snd_firewire_event_lock_status event = {
+               .type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
+       };
+
+       event.status = (tscm->dev_lock_count > 0);
+       tscm->dev_lock_changed = false;
+       count = min_t(long, count, sizeof(event));
+
+       spin_unlock_irq(&tscm->lock);
+
+       if (copy_to_user(buf, &event, count))
+               return -EFAULT;
+
+       return count;
+}
+
 static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
                       loff_t *offset)
 {
        struct snd_tscm *tscm = hwdep->private_data;
        DEFINE_WAIT(wait);
-       union snd_firewire_event event = {
-               .lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
-       };
 
        spin_lock_irq(&tscm->lock);
 
@@ -37,15 +53,13 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
                spin_lock_irq(&tscm->lock);
        }
 
-       event.lock_status.status = (tscm->dev_lock_count > 0);
-       tscm->dev_lock_changed = false;
-
-       spin_unlock_irq(&tscm->lock);
-
-       count = min_t(long, count, sizeof(event.lock_status));
-
-       if (copy_to_user(buf, &event, count))
-               return -EFAULT;
+       // NOTE: The acquired lock should be released in callee side.
+       if (tscm->dev_lock_changed) {
+               count = tscm_hwdep_read_locked(tscm, buf, count, offset);
+       } else {
+               spin_unlock_irq(&tscm->lock);
+               count = 0;
+       }
 
        return count;
 }