int snd_find_minor(int type, int card_num, int dev) { if (snd_BUG_ON(card_num < 0 || card_num >= SNDRV_CARDS)) return -EINVAL; return find_snd_minor(type, snd_cards[card_num], dev); }
int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, struct device_attribute *attr) { int minor, ret = -EINVAL; struct device *d; mutex_lock(&sound_mutex); minor = find_snd_minor(type, card, dev); if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL) ret = device_create_file(d, attr); mutex_unlock(&sound_mutex); return ret; }
/* get the assigned device to the given type and device number; * the caller needs to release it via put_device() after using it */ struct device *snd_get_device(int type, struct snd_card *card, int dev) { int minor; struct device *d = NULL; mutex_lock(&sound_mutex); minor = find_snd_minor(type, card, dev); if (minor >= 0) { d = snd_minors[minor]->dev; if (d) get_device(d); } mutex_unlock(&sound_mutex); return d; }
/** * snd_unregister_device - unregister the device on the given card * @type: the device type, SNDRV_DEVICE_TYPE_XXX * @card: the card instance * @dev: the device index * * Unregisters the device file already registered via * snd_register_device(). * * Returns zero if sucecessful, or a negative error code on failure */ int snd_unregister_device(int type, struct snd_card *card, int dev) { int minor; mutex_lock(&sound_mutex); minor = find_snd_minor(type, card, dev); if (minor < 0) { mutex_unlock(&sound_mutex); return -EINVAL; } device_destroy(sound_class, MKDEV(major, minor)); kfree(snd_minors[minor]); snd_minors[minor] = NULL; mutex_unlock(&sound_mutex); return 0; }