diff options
| -rw-r--r-- | include/sound/core.h | 3 | ||||
| -rw-r--r-- | sound/core/compress_offload.c | 9 | ||||
| -rw-r--r-- | sound/core/control.c | 3 | ||||
| -rw-r--r-- | sound/core/hwdep.c | 5 | ||||
| -rw-r--r-- | sound/core/init.c | 50 | ||||
| -rw-r--r-- | sound/core/oss/mixer_oss.c | 10 | ||||
| -rw-r--r-- | sound/core/oss/pcm_oss.c | 2 | ||||
| -rw-r--r-- | sound/core/pcm_native.c | 9 | ||||
| -rw-r--r-- | sound/core/rawmidi.c | 6 | ||||
| -rw-r--r-- | sound/core/sound.c | 11 | ||||
| -rw-r--r-- | sound/core/sound_oss.c | 10 |
11 files changed, 86 insertions, 32 deletions
diff --git a/include/sound/core.h b/include/sound/core.h index bc056687f647..93896ad1fcdd 100644 --- a/include/sound/core.h +++ b/include/sound/core.h | |||
| @@ -132,6 +132,7 @@ struct snd_card { | |||
| 132 | int shutdown; /* this card is going down */ | 132 | int shutdown; /* this card is going down */ |
| 133 | int free_on_last_close; /* free in context of file_release */ | 133 | int free_on_last_close; /* free in context of file_release */ |
| 134 | wait_queue_head_t shutdown_sleep; | 134 | wait_queue_head_t shutdown_sleep; |
| 135 | atomic_t refcount; /* refcount for disconnection */ | ||
| 135 | struct device *dev; /* device assigned to this card */ | 136 | struct device *dev; /* device assigned to this card */ |
| 136 | struct device *card_dev; /* cardX object for sysfs */ | 137 | struct device *card_dev; /* cardX object for sysfs */ |
| 137 | 138 | ||
| @@ -189,6 +190,7 @@ struct snd_minor { | |||
| 189 | const struct file_operations *f_ops; /* file operations */ | 190 | const struct file_operations *f_ops; /* file operations */ |
| 190 | void *private_data; /* private data for f_ops->open */ | 191 | void *private_data; /* private data for f_ops->open */ |
| 191 | struct device *dev; /* device for sysfs */ | 192 | struct device *dev; /* device for sysfs */ |
| 193 | struct snd_card *card_ptr; /* assigned card instance */ | ||
| 192 | }; | 194 | }; |
| 193 | 195 | ||
| 194 | /* return a device pointer linked to each sound device as a parent */ | 196 | /* return a device pointer linked to each sound device as a parent */ |
| @@ -295,6 +297,7 @@ int snd_card_info_done(void); | |||
| 295 | int snd_component_add(struct snd_card *card, const char *component); | 297 | int snd_component_add(struct snd_card *card, const char *component); |
| 296 | int snd_card_file_add(struct snd_card *card, struct file *file); | 298 | int snd_card_file_add(struct snd_card *card, struct file *file); |
| 297 | int snd_card_file_remove(struct snd_card *card, struct file *file); | 299 | int snd_card_file_remove(struct snd_card *card, struct file *file); |
| 300 | void snd_card_unref(struct snd_card *card); | ||
| 298 | 301 | ||
| 299 | #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr)) | 302 | #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr)) |
| 300 | 303 | ||
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index c40ae573346d..ad11dc994792 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c | |||
| @@ -100,12 +100,15 @@ static int snd_compr_open(struct inode *inode, struct file *f) | |||
| 100 | 100 | ||
| 101 | if (dirn != compr->direction) { | 101 | if (dirn != compr->direction) { |
| 102 | pr_err("this device doesn't support this direction\n"); | 102 | pr_err("this device doesn't support this direction\n"); |
| 103 | snd_card_unref(compr->card); | ||
| 103 | return -EINVAL; | 104 | return -EINVAL; |
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 107 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 107 | if (!data) | 108 | if (!data) { |
| 109 | snd_card_unref(compr->card); | ||
| 108 | return -ENOMEM; | 110 | return -ENOMEM; |
| 111 | } | ||
| 109 | data->stream.ops = compr->ops; | 112 | data->stream.ops = compr->ops; |
| 110 | data->stream.direction = dirn; | 113 | data->stream.direction = dirn; |
| 111 | data->stream.private_data = compr->private_data; | 114 | data->stream.private_data = compr->private_data; |
| @@ -113,6 +116,7 @@ static int snd_compr_open(struct inode *inode, struct file *f) | |||
| 113 | runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); | 116 | runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); |
| 114 | if (!runtime) { | 117 | if (!runtime) { |
| 115 | kfree(data); | 118 | kfree(data); |
| 119 | snd_card_unref(compr->card); | ||
| 116 | return -ENOMEM; | 120 | return -ENOMEM; |
| 117 | } | 121 | } |
| 118 | runtime->state = SNDRV_PCM_STATE_OPEN; | 122 | runtime->state = SNDRV_PCM_STATE_OPEN; |
| @@ -126,7 +130,8 @@ static int snd_compr_open(struct inode *inode, struct file *f) | |||
| 126 | kfree(runtime); | 130 | kfree(runtime); |
| 127 | kfree(data); | 131 | kfree(data); |
| 128 | } | 132 | } |
| 129 | return ret; | 133 | snd_card_unref(compr->card); |
| 134 | return 0; | ||
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | static int snd_compr_free(struct inode *inode, struct file *f) | 137 | static int snd_compr_free(struct inode *inode, struct file *f) |
diff --git a/sound/core/control.c b/sound/core/control.c index 7e86a5b9f3b5..9768a3963c8f 100644 --- a/sound/core/control.c +++ b/sound/core/control.c | |||
| @@ -86,6 +86,7 @@ static int snd_ctl_open(struct inode *inode, struct file *file) | |||
| 86 | write_lock_irqsave(&card->ctl_files_rwlock, flags); | 86 | write_lock_irqsave(&card->ctl_files_rwlock, flags); |
| 87 | list_add_tail(&ctl->list, &card->ctl_files); | 87 | list_add_tail(&ctl->list, &card->ctl_files); |
| 88 | write_unlock_irqrestore(&card->ctl_files_rwlock, flags); | 88 | write_unlock_irqrestore(&card->ctl_files_rwlock, flags); |
| 89 | snd_card_unref(card); | ||
| 89 | return 0; | 90 | return 0; |
| 90 | 91 | ||
| 91 | __error: | 92 | __error: |
| @@ -93,6 +94,8 @@ static int snd_ctl_open(struct inode *inode, struct file *file) | |||
| 93 | __error2: | 94 | __error2: |
| 94 | snd_card_file_remove(card, file); | 95 | snd_card_file_remove(card, file); |
| 95 | __error1: | 96 | __error1: |
| 97 | if (card) | ||
| 98 | snd_card_unref(card); | ||
| 96 | return err; | 99 | return err; |
| 97 | } | 100 | } |
| 98 | 101 | ||
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c index 75ea16f35b1a..53a6ba5ad615 100644 --- a/sound/core/hwdep.c +++ b/sound/core/hwdep.c | |||
| @@ -100,8 +100,10 @@ static int snd_hwdep_open(struct inode *inode, struct file * file) | |||
| 100 | if (hw == NULL) | 100 | if (hw == NULL) |
| 101 | return -ENODEV; | 101 | return -ENODEV; |
| 102 | 102 | ||
| 103 | if (!try_module_get(hw->card->module)) | 103 | if (!try_module_get(hw->card->module)) { |
| 104 | snd_card_unref(hw->card); | ||
| 104 | return -EFAULT; | 105 | return -EFAULT; |
| 106 | } | ||
| 105 | 107 | ||
| 106 | init_waitqueue_entry(&wait, current); | 108 | init_waitqueue_entry(&wait, current); |
| 107 | add_wait_queue(&hw->open_wait, &wait); | 109 | add_wait_queue(&hw->open_wait, &wait); |
| @@ -148,6 +150,7 @@ static int snd_hwdep_open(struct inode *inode, struct file * file) | |||
| 148 | mutex_unlock(&hw->open_mutex); | 150 | mutex_unlock(&hw->open_mutex); |
| 149 | if (err < 0) | 151 | if (err < 0) |
| 150 | module_put(hw->card->module); | 152 | module_put(hw->card->module); |
| 153 | snd_card_unref(hw->card); | ||
| 151 | return err; | 154 | return err; |
| 152 | } | 155 | } |
| 153 | 156 | ||
diff --git a/sound/core/init.c b/sound/core/init.c index d8ec849af128..7b012d15c2cf 100644 --- a/sound/core/init.c +++ b/sound/core/init.c | |||
| @@ -213,6 +213,7 @@ int snd_card_create(int idx, const char *xid, | |||
| 213 | spin_lock_init(&card->files_lock); | 213 | spin_lock_init(&card->files_lock); |
| 214 | INIT_LIST_HEAD(&card->files_list); | 214 | INIT_LIST_HEAD(&card->files_list); |
| 215 | init_waitqueue_head(&card->shutdown_sleep); | 215 | init_waitqueue_head(&card->shutdown_sleep); |
| 216 | atomic_set(&card->refcount, 0); | ||
| 216 | #ifdef CONFIG_PM | 217 | #ifdef CONFIG_PM |
| 217 | mutex_init(&card->power_lock); | 218 | mutex_init(&card->power_lock); |
| 218 | init_waitqueue_head(&card->power_sleep); | 219 | init_waitqueue_head(&card->power_sleep); |
| @@ -446,21 +447,36 @@ static int snd_card_do_free(struct snd_card *card) | |||
| 446 | return 0; | 447 | return 0; |
| 447 | } | 448 | } |
| 448 | 449 | ||
| 450 | /** | ||
| 451 | * snd_card_unref - release the reference counter | ||
| 452 | * @card: the card instance | ||
| 453 | * | ||
| 454 | * Decrements the reference counter. When it reaches to zero, wake up | ||
| 455 | * the sleeper and call the destructor if needed. | ||
| 456 | */ | ||
| 457 | void snd_card_unref(struct snd_card *card) | ||
| 458 | { | ||
| 459 | if (atomic_dec_and_test(&card->refcount)) { | ||
| 460 | wake_up(&card->shutdown_sleep); | ||
| 461 | if (card->free_on_last_close) | ||
| 462 | snd_card_do_free(card); | ||
| 463 | } | ||
| 464 | } | ||
| 465 | EXPORT_SYMBOL(snd_card_unref); | ||
| 466 | |||
| 449 | int snd_card_free_when_closed(struct snd_card *card) | 467 | int snd_card_free_when_closed(struct snd_card *card) |
| 450 | { | 468 | { |
| 451 | int free_now = 0; | 469 | int ret; |
| 452 | int ret = snd_card_disconnect(card); | ||
| 453 | if (ret) | ||
| 454 | return ret; | ||
| 455 | 470 | ||
| 456 | spin_lock(&card->files_lock); | 471 | atomic_inc(&card->refcount); |
| 457 | if (list_empty(&card->files_list)) | 472 | ret = snd_card_disconnect(card); |
| 458 | free_now = 1; | 473 | if (ret) { |
| 459 | else | 474 | atomic_dec(&card->refcount); |
| 460 | card->free_on_last_close = 1; | 475 | return ret; |
