History

ALSA: Add a reference counter to card instance

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.

Takashi Iwai committed 14 years ago

Commit a0830db1 parent 888ea7d11 files · +86 −32Browse files

Showing the changes to include/sound (1 of 11 files). Show all

Unified · Split

include/sound/core.h+3−0
@@ -132,6 +132,7 @@ struct snd_card { · 131 unmodified lines
132132 int shutdown; /* this card is going down */
133133 int free_on_last_close; /* free in context of file_release */
134134 wait_queue_head_t shutdown_sleep;
135+ atomic_t refcount; /* refcount for disconnection */
135136 struct device *dev; /* device assigned to this card */
136137 struct device *card_dev; /* cardX object for sysfs */
137138
@@ -189,6 +190,7 @@ struct snd_minor { · 51 unmodified lines
189190 const struct file_operations *f_ops; /* file operations */
190191 void *private_data; /* private data for f_ops->open */
191192 struct device *dev; /* device for sysfs */
193+ struct snd_card *card_ptr; /* assigned card instance */
192194 };
193195
194196 /* return a device pointer linked to each sound device as a parent */
@@ -295,6 +297,7 @@ int snd_card_info_done(void); · 100 unmodified lines
295297 int snd_component_add(struct snd_card *card, const char *component);
296298 int snd_card_file_add(struct snd_card *card, struct file *file);
297299 int snd_card_file_remove(struct snd_card *card, struct file *file);
300+void snd_card_unref(struct snd_card *card);
298301
299302 #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
300303