diff options
author | Takashi Iwai <tiwai@suse.de> | 2014-02-19 08:30:29 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-02-02 08:21:21 -0500 |
commit | 23c18d4bfd73ee24070849faf98b3ab01263a3c4 (patch) | |
tree | 944e0e24bd847fdbbddd8baf5ab0976c0fdcfa81 /sound/core/control.c | |
parent | 92b7952da8279189aad352efbf9f2e7001de9524 (diff) |
ALSA: control: Provide a helper to look for the preferred subdevice
Instead of open-coding the search over the control file loop, provide
a helper function for the preferred subdevice assigned to the current
process.
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core/control.c')
-rw-r--r-- | sound/core/control.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/sound/core/control.c b/sound/core/control.c index bb96a467e88d..cd246a0bcd55 100644 --- a/sound/core/control.c +++ b/sound/core/control.c | |||
@@ -50,7 +50,7 @@ static int snd_ctl_open(struct inode *inode, struct file *file) | |||
50 | unsigned long flags; | 50 | unsigned long flags; |
51 | struct snd_card *card; | 51 | struct snd_card *card; |
52 | struct snd_ctl_file *ctl; | 52 | struct snd_ctl_file *ctl; |
53 | int err; | 53 | int i, err; |
54 | 54 | ||
55 | err = nonseekable_open(inode, file); | 55 | err = nonseekable_open(inode, file); |
56 | if (err < 0) | 56 | if (err < 0) |
@@ -79,8 +79,8 @@ static int snd_ctl_open(struct inode *inode, struct file *file) | |||
79 | init_waitqueue_head(&ctl->change_sleep); | 79 | init_waitqueue_head(&ctl->change_sleep); |
80 | spin_lock_init(&ctl->read_lock); | 80 | spin_lock_init(&ctl->read_lock); |
81 | ctl->card = card; | 81 | ctl->card = card; |
82 | ctl->prefer_pcm_subdevice = -1; | 82 | for (i = 0; i < SND_CTL_SUBDEV_ITEMS; i++) |
83 | ctl->prefer_rawmidi_subdevice = -1; | 83 | ctl->preferred_subdevice[i] = -1; |
84 | ctl->pid = get_pid(task_pid(current)); | 84 | ctl->pid = get_pid(task_pid(current)); |
85 | file->private_data = ctl; | 85 | file->private_data = ctl; |
86 | write_lock_irqsave(&card->ctl_files_rwlock, flags); | 86 | write_lock_irqsave(&card->ctl_files_rwlock, flags); |
@@ -1607,6 +1607,27 @@ static int snd_ctl_fasync(int fd, struct file * file, int on) | |||
1607 | return fasync_helper(fd, file, on, &ctl->fasync); | 1607 | return fasync_helper(fd, file, on, &ctl->fasync); |
1608 | } | 1608 | } |
1609 | 1609 | ||
1610 | /* return the preferred subdevice number if already assigned; | ||
1611 | * otherwise return -1 | ||
1612 | */ | ||
1613 | int snd_ctl_get_preferred_subdevice(struct snd_card *card, int type) | ||
1614 | { | ||
1615 | struct snd_ctl_file *kctl; | ||
1616 | int subdevice = -1; | ||
1617 | |||
1618 | read_lock(&card->ctl_files_rwlock); | ||
1619 | list_for_each_entry(kctl, &card->ctl_files, list) { | ||
1620 | if (kctl->pid == task_pid(current)) { | ||
1621 | subdevice = kctl->preferred_subdevice[type]; | ||
1622 | if (subdevice != -1) | ||
1623 | break; | ||
1624 | } | ||
1625 | } | ||
1626 | read_unlock(&card->ctl_files_rwlock); | ||
1627 | return subdevice; | ||
1628 | } | ||
1629 | EXPORT_SYMBOL_GPL(snd_ctl_get_preferred_subdevice); | ||
1630 | |||
1610 | /* | 1631 | /* |
1611 | * ioctl32 compat | 1632 | * ioctl32 compat |
1612 | */ | 1633 | */ |