aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/rawmidi.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2006-06-23 08:38:23 -0400
committerJaroslav Kysela <perex@suse.cz>2006-09-23 04:36:58 -0400
commitc461482c8072bb073e6146db320d3da85cdc89ad (patch)
tree3b69cfd292a488a8cb57ac9b040bd2b1b1a1e26d /sound/core/rawmidi.c
parent746d4a02e68499fc6c1f8d0c43d2271853ade181 (diff)
[ALSA] Unregister device files at disconnection
Orignally proposed by Sam Revitch <sam.revitch@gmail.com>. Unregister device files at disconnection to avoid the futher accesses. Also, the dev_unregister callback is removed and replaced with the combination of disconnect + free. A new function snd_card_free_when_closed() is introduced, which is used in USB disconnect callback. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/core/rawmidi.c')
-rw-r--r--sound/core/rawmidi.c35
1 files changed, 9 insertions, 26 deletions
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 51577c22f8ce..8a2bdfae63e3 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -55,7 +55,6 @@ static int snd_rawmidi_free(struct snd_rawmidi *rawmidi);
55static int snd_rawmidi_dev_free(struct snd_device *device); 55static int snd_rawmidi_dev_free(struct snd_device *device);
56static int snd_rawmidi_dev_register(struct snd_device *device); 56static int snd_rawmidi_dev_register(struct snd_device *device);
57static int snd_rawmidi_dev_disconnect(struct snd_device *device); 57static int snd_rawmidi_dev_disconnect(struct snd_device *device);
58static int snd_rawmidi_dev_unregister(struct snd_device *device);
59 58
60static LIST_HEAD(snd_rawmidi_devices); 59static LIST_HEAD(snd_rawmidi_devices);
61static DEFINE_MUTEX(register_mutex); 60static DEFINE_MUTEX(register_mutex);
@@ -1426,7 +1425,6 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
1426 .dev_free = snd_rawmidi_dev_free, 1425 .dev_free = snd_rawmidi_dev_free,
1427 .dev_register = snd_rawmidi_dev_register, 1426 .dev_register = snd_rawmidi_dev_register,
1428 .dev_disconnect = snd_rawmidi_dev_disconnect, 1427 .dev_disconnect = snd_rawmidi_dev_disconnect,
1429 .dev_unregister = snd_rawmidi_dev_unregister
1430 }; 1428 };
1431 1429
1432 snd_assert(rrawmidi != NULL, return -EINVAL); 1430 snd_assert(rrawmidi != NULL, return -EINVAL);
@@ -1479,6 +1477,14 @@ static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream)
1479static int snd_rawmidi_free(struct snd_rawmidi *rmidi) 1477static int snd_rawmidi_free(struct snd_rawmidi *rmidi)
1480{ 1478{
1481 snd_assert(rmidi != NULL, return -ENXIO); 1479 snd_assert(rmidi != NULL, return -ENXIO);
1480
1481 snd_info_free_entry(rmidi->proc_entry);
1482 rmidi->proc_entry = NULL;
1483 mutex_lock(&register_mutex);
1484 if (rmidi->ops && rmidi->ops->dev_unregister)
1485 rmidi->ops->dev_unregister(rmidi);
1486 mutex_unlock(&register_mutex);
1487
1482 snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]); 1488 snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]);
1483 snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); 1489 snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]);
1484 if (rmidi->private_free) 1490 if (rmidi->private_free)
@@ -1587,21 +1593,6 @@ static int snd_rawmidi_dev_disconnect(struct snd_device *device)
1587 1593
1588 mutex_lock(&register_mutex); 1594 mutex_lock(&register_mutex);
1589 list_del_init(&rmidi->list); 1595 list_del_init(&rmidi->list);
1590 mutex_unlock(&register_mutex);
1591 return 0;
1592}
1593
1594static int snd_rawmidi_dev_unregister(struct snd_device *device)
1595{
1596 struct snd_rawmidi *rmidi = device->device_data;
1597
1598 snd_assert(rmidi != NULL, return -ENXIO);
1599 mutex_lock(&register_mutex);
1600 list_del(&rmidi->list);
1601 if (rmidi->proc_entry) {
1602 snd_info_free_entry(rmidi->proc_entry);
1603 rmidi->proc_entry = NULL;
1604 }
1605#ifdef CONFIG_SND_OSSEMUL 1596#ifdef CONFIG_SND_OSSEMUL
1606 if (rmidi->ossreg) { 1597 if (rmidi->ossreg) {
1607 if ((int)rmidi->device == midi_map[rmidi->card->number]) { 1598 if ((int)rmidi->device == midi_map[rmidi->card->number]) {
@@ -1615,17 +1606,9 @@ static int snd_rawmidi_dev_unregister(struct snd_device *device)
1615 rmidi->ossreg = 0; 1606 rmidi->ossreg = 0;
1616 } 1607 }
1617#endif /* CONFIG_SND_OSSEMUL */ 1608#endif /* CONFIG_SND_OSSEMUL */
1618 if (rmidi->ops && rmidi->ops->dev_unregister)
1619 rmidi->ops->dev_unregister(rmidi);
1620 snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device); 1609 snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
1621 mutex_unlock(&register_mutex); 1610 mutex_unlock(&register_mutex);
1622#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) 1611 return 0;
1623 if (rmidi->seq_dev) {
1624 snd_device_free(rmidi->card, rmidi->seq_dev);
1625 rmidi->seq_dev = NULL;
1626 }
1627#endif
1628 return snd_rawmidi_free(rmidi);
1629} 1612}
1630 1613
1631/** 1614/**