Commit 746df948 authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[ALSA] Fix rwlock around snd_iprintf() in sound core

Fixed rwlock around snd_iprintf() in sound core part.
Replaced with mutex.
Also, make mutex and flags static variables with addition of
snd_card_locked() function (just for sound.c).
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 0defb267
...@@ -233,9 +233,8 @@ int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size ...@@ -233,9 +233,8 @@ int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size
/* init.c */ /* init.c */
extern unsigned int snd_cards_lock;
extern struct snd_card *snd_cards[SNDRV_CARDS]; extern struct snd_card *snd_cards[SNDRV_CARDS];
extern rwlock_t snd_card_rwlock; int snd_card_locked(int card);
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
#define SND_MIXER_OSS_NOTIFY_REGISTER 0 #define SND_MIXER_OSS_NOTIFY_REGISTER 0
#define SND_MIXER_OSS_NOTIFY_DISCONNECT 1 #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
......
...@@ -38,11 +38,11 @@ struct snd_shutdown_f_ops { ...@@ -38,11 +38,11 @@ struct snd_shutdown_f_ops {
struct snd_shutdown_f_ops *next; struct snd_shutdown_f_ops *next;
}; };
unsigned int snd_cards_lock = 0; /* locked for registering/using */ static unsigned int snd_cards_lock = 0; /* locked for registering/using */
struct snd_card *snd_cards[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = NULL}; struct snd_card *snd_cards[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = NULL};
EXPORT_SYMBOL(snd_cards); EXPORT_SYMBOL(snd_cards);
DEFINE_RWLOCK(snd_card_rwlock); static DEFINE_MUTEX(snd_card_mutex);
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag); int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag);
...@@ -112,7 +112,7 @@ struct snd_card *snd_card_new(int idx, const char *xid, ...@@ -112,7 +112,7 @@ struct snd_card *snd_card_new(int idx, const char *xid,
strlcpy(card->id, xid, sizeof(card->id)); strlcpy(card->id, xid, sizeof(card->id));
} }
err = 0; err = 0;
write_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
if (idx < 0) { if (idx < 0) {
int idx2; int idx2;
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
...@@ -130,12 +130,12 @@ struct snd_card *snd_card_new(int idx, const char *xid, ...@@ -130,12 +130,12 @@ struct snd_card *snd_card_new(int idx, const char *xid,
else else
err = -ENODEV; err = -ENODEV;
if (idx < 0 || err < 0) { if (idx < 0 || err < 0) {
write_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i)\n", idx, snd_ecards_limit - 1); snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i)\n", idx, snd_ecards_limit - 1);
goto __error; goto __error;
} }
snd_cards_lock |= 1 << idx; /* lock it */ snd_cards_lock |= 1 << idx; /* lock it */
write_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
card->number = idx; card->number = idx;
card->module = module; card->module = module;
INIT_LIST_HEAD(&card->devices); INIT_LIST_HEAD(&card->devices);
...@@ -173,6 +173,17 @@ struct snd_card *snd_card_new(int idx, const char *xid, ...@@ -173,6 +173,17 @@ struct snd_card *snd_card_new(int idx, const char *xid,
EXPORT_SYMBOL(snd_card_new); EXPORT_SYMBOL(snd_card_new);
/* return non-zero if a card is already locked */
int snd_card_locked(int card)
{
int locked;
mutex_lock(&snd_card_mutex);
locked = snd_cards_lock & (1 << card);
mutex_unlock(&snd_card_mutex);
return locked;
}
static loff_t snd_disconnect_llseek(struct file *file, loff_t offset, int orig) static loff_t snd_disconnect_llseek(struct file *file, loff_t offset, int orig)
{ {
return -ENODEV; return -ENODEV;
...@@ -240,9 +251,9 @@ int snd_card_disconnect(struct snd_card *card) ...@@ -240,9 +251,9 @@ int snd_card_disconnect(struct snd_card *card)
spin_unlock(&card->files_lock); spin_unlock(&card->files_lock);
/* phase 1: disable fops (user space) operations for ALSA API */ /* phase 1: disable fops (user space) operations for ALSA API */
write_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
snd_cards[card->number] = NULL; snd_cards[card->number] = NULL;
write_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
/* phase 2: replace file->f_op with special dummy operations */ /* phase 2: replace file->f_op with special dummy operations */
...@@ -321,9 +332,9 @@ int snd_card_free(struct snd_card *card) ...@@ -321,9 +332,9 @@ int snd_card_free(struct snd_card *card)
if (card == NULL) if (card == NULL)
return -EINVAL; return -EINVAL;
write_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
snd_cards[card->number] = NULL; snd_cards[card->number] = NULL;
write_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
#ifdef CONFIG_PM #ifdef CONFIG_PM
wake_up(&card->power_sleep); wake_up(&card->power_sleep);
...@@ -359,9 +370,9 @@ int snd_card_free(struct snd_card *card) ...@@ -359,9 +370,9 @@ int snd_card_free(struct snd_card *card)
card->s_f_ops = s_f_ops->next; card->s_f_ops = s_f_ops->next;
kfree(s_f_ops); kfree(s_f_ops);
} }
write_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
snd_cards_lock &= ~(1 << card->number); snd_cards_lock &= ~(1 << card->number);
write_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
kfree(card); kfree(card);
return 0; return 0;
} }
...@@ -497,16 +508,16 @@ int snd_card_register(struct snd_card *card) ...@@ -497,16 +508,16 @@ int snd_card_register(struct snd_card *card)
snd_assert(card != NULL, return -EINVAL); snd_assert(card != NULL, return -EINVAL);
if ((err = snd_device_register_all(card)) < 0) if ((err = snd_device_register_all(card)) < 0)
return err; return err;
write_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
if (snd_cards[card->number]) { if (snd_cards[card->number]) {
/* already registered */ /* already registered */
write_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
return 0; return 0;
} }
if (card->id[0] == '\0') if (card->id[0] == '\0')
choose_default_id(card); choose_default_id(card);
snd_cards[card->number] = card; snd_cards[card->number] = card;
write_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
init_info_for_card(card); init_info_for_card(card);
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
if (snd_mixer_oss_notify_callback) if (snd_mixer_oss_notify_callback)
...@@ -527,7 +538,7 @@ static void snd_card_info_read(struct snd_info_entry *entry, ...@@ -527,7 +538,7 @@ static void snd_card_info_read(struct snd_info_entry *entry,
struct snd_card *card; struct snd_card *card;
for (idx = count = 0; idx < SNDRV_CARDS; idx++) { for (idx = count = 0; idx < SNDRV_CARDS; idx++) {
read_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
if ((card = snd_cards[idx]) != NULL) { if ((card = snd_cards[idx]) != NULL) {
count++; count++;
snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n", snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n",
...@@ -538,7 +549,7 @@ static void snd_card_info_read(struct snd_info_entry *entry, ...@@ -538,7 +549,7 @@ static void snd_card_info_read(struct snd_info_entry *entry,
snd_iprintf(buffer, " %s\n", snd_iprintf(buffer, " %s\n",
card->longname); card->longname);
} }
read_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
} }
if (!count) if (!count)
snd_iprintf(buffer, "--- no soundcards ---\n"); snd_iprintf(buffer, "--- no soundcards ---\n");
...@@ -552,12 +563,12 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer) ...@@ -552,12 +563,12 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer)
struct snd_card *card; struct snd_card *card;
for (idx = count = 0; idx < SNDRV_CARDS; idx++) { for (idx = count = 0; idx < SNDRV_CARDS; idx++) {
read_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
if ((card = snd_cards[idx]) != NULL) { if ((card = snd_cards[idx]) != NULL) {
count++; count++;
snd_iprintf(buffer, "%s\n", card->longname); snd_iprintf(buffer, "%s\n", card->longname);
} }
read_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
} }
if (!count) { if (!count) {
snd_iprintf(buffer, "--- no soundcards ---\n"); snd_iprintf(buffer, "--- no soundcards ---\n");
...@@ -575,11 +586,11 @@ static void snd_card_module_info_read(struct snd_info_entry *entry, ...@@ -575,11 +586,11 @@ static void snd_card_module_info_read(struct snd_info_entry *entry,
struct snd_card *card; struct snd_card *card;
for (idx = 0; idx < SNDRV_CARDS; idx++) { for (idx = 0; idx < SNDRV_CARDS; idx++) {
read_lock(&snd_card_rwlock); mutex_lock(&snd_card_mutex);
if ((card = snd_cards[idx]) != NULL) if ((card = snd_cards[idx]) != NULL)
snd_iprintf(buffer, "%2i %s\n", snd_iprintf(buffer, "%2i %s\n",
idx, card->module->name); idx, card->module->name);
read_unlock(&snd_card_rwlock); mutex_unlock(&snd_card_mutex);
} }
} }
#endif #endif
......
...@@ -81,14 +81,9 @@ extern struct class *sound_class; ...@@ -81,14 +81,9 @@ extern struct class *sound_class;
*/ */
void snd_request_card(int card) void snd_request_card(int card)
{ {
int locked;
if (! current->fs->root) if (! current->fs->root)
return; return;
read_lock(&snd_card_rwlock); if (snd_card_locked(card))
locked = snd_cards_lock & (1 << card);
read_unlock(&snd_card_rwlock);
if (locked)
return; return;
if (card < 0 || card >= cards_limit) if (card < 0 || card >= cards_limit)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment