diff options
author | Takashi Iwai <tiwai@suse.de> | 2012-10-16 15:05:59 +0400 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2012-11-16 20:46:50 +0400 |
commit | 3b4a36722e5e518e4bdd3a215d8a1c5adc18e911 (patch) | |
tree | 3db0ebb96a886ce6ff3c91e60510a03b561a20bc /sound/core/sound_oss.c | |
parent | f6415ce55f2430e38f674d8421511e489b2c71b0 (diff) | |
download | linux-3b4a36722e5e518e4bdd3a215d8a1c5adc18e911.tar.xz |
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: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'sound/core/sound_oss.c')
-rw-r--r-- | sound/core/sound_oss.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/sound/core/sound_oss.c b/sound/core/sound_oss.c index c70092043061..7442c7ac2469 100644 --- a/sound/core/sound_oss.c +++ b/sound/core/sound_oss.c @@ -40,6 +40,9 @@ static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS]; static DEFINE_MUTEX(sound_oss_mutex); +/* NOTE: This function increments the refcount of the associated card like + * snd_lookup_minor_data(); the caller must call snd_card_unref() appropriately + */ void *snd_lookup_oss_minor_data(unsigned int minor, int type) { struct snd_minor *mreg; @@ -49,9 +52,11 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type) return NULL; mutex_lock(&sound_oss_mutex); mreg = snd_oss_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_oss_mutex); return private_data; @@ -123,6 +128,7 @@ int snd_register_oss_device(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_oss_mutex); snd_oss_minors[minor] = preg; minor_unit = SNDRV_MINOR_OSS_DEVICE(minor); |