aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/sound.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-11-07 12:44:12 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-17 13:14:22 -0800
commit40edba667959559aa4385a5ec047420fcfeb5f03 (patch)
tree6df9fc6d71f5d7608a95ca7d437fca00b83afb1f /sound/core/sound.c
parentfb434cc26173c2285d48d640c639493bc6a6c5f5 (diff)
downloadkernel_samsung_smdk4412-40edba667959559aa4385a5ec047420fcfeb5f03.zip
kernel_samsung_smdk4412-40edba667959559aa4385a5ec047420fcfeb5f03.tar.gz
kernel_samsung_smdk4412-40edba667959559aa4385a5ec047420fcfeb5f03.tar.bz2
ALSA: Add a reference counter to card instance
commit a0830dbd4e42b38aefdf3fb61ba5019a1a99ea85 upstream. For more strict protection for wild disconnections, a refcount is introduced to the card instance, and let it up/down when an object is referred via snd_lookup_*() in the open ops. The free-after-last-close check is also changed to check this refcount instead of the empty list, too. Reported-by: Matthieu CASTET <matthieu.castet@parrot.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'sound/core/sound.c')
-rw-r--r--sound/core/sound.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 1c7a3ef..b235aaa 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -99,6 +99,10 @@ static void snd_request_other(int minor)
*
* Checks that a minor device with the specified type is registered, and returns
* its user data pointer.
+ *
+ * This function increments the reference counter of the card instance
+ * if an associated instance with the given minor number and type is found.
+ * The caller must call snd_card_unref() appropriately later.
*/
void *snd_lookup_minor_data(unsigned int minor, int type)
{
@@ -109,9 +113,11 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
return NULL;
mutex_lock(&sound_mutex);
mreg = snd_minors[minor];
- if (mreg && mreg->type == type)
+ if (mreg && mreg->type == type) {
private_data = mreg->private_data;
- else
+ if (mreg->card_ptr)
+ atomic_inc(&mreg->card_ptr->refcount);
+ } else
private_data = NULL;
mutex_unlock(&sound_mutex);
return private_data;
@@ -275,6 +281,7 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
preg->device = dev;
preg->f_ops = f_ops;
preg->private_data = private_data;
+ preg->card_ptr = card;
mutex_lock(&sound_mutex);
#ifdef CONFIG_SND_DYNAMIC_MINORS
minor = snd_find_free_minor(type);