/** * snd_hwdep_new - create a new hwdep instance * @card: the card instance * @id: the id string * @device: the device index (zero-based) * @rhwdep: the pointer to store the new hwdep instance * * Creates a new hwdep instance with the given index on the card. * The callbacks (hwdep->ops) must be set on the returned instance * after this call manually by the caller. * * Returns zero if successful, or a negative error code on failure. */ int snd_hwdep_new(snd_card_t * card, char *id, int device, snd_hwdep_t ** rhwdep) { snd_hwdep_t *hwdep; int err; static snd_device_ops_t ops = { .dev_free = snd_hwdep_dev_free, .dev_register = snd_hwdep_dev_register, .dev_unregister = snd_hwdep_dev_unregister }; snd_assert(rhwdep != NULL, return -EINVAL); *rhwdep = NULL; snd_assert(card != NULL, return -ENXIO); hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); if (hwdep == NULL) return -ENOMEM; hwdep->card = card; hwdep->device = device; if (id) { strlcpy(hwdep->id, id, sizeof(hwdep->id)); } #ifdef CONFIG_SND_OSSEMUL hwdep->oss_type = -1; #endif if ((err = snd_device_new(card, SNDRV_DEV_HWDEP, hwdep, &ops)) < 0) { snd_hwdep_free(hwdep); return err; } init_waitqueue_head(&hwdep->open_wait); init_MUTEX(&hwdep->open_mutex); *rhwdep = hwdep; return 0; }
/** * snd_hwdep_new - create a new hwdep instance * @card: the card instance * @id: the id string * @device: the device index (zero-based) * @rhwdep: the pointer to store the new hwdep instance * * Creates a new hwdep instance with the given index on the card. * The callbacks (hwdep->ops) must be set on the returned instance * after this call manually by the caller. * * Returns zero if successful, or a negative error code on failure. */ int snd_hwdep_new(struct snd_card *card, char *id, int device, struct snd_hwdep **rhwdep) { struct snd_hwdep *hwdep; int err; static struct snd_device_ops ops = { .dev_free = snd_hwdep_dev_free, .dev_register = snd_hwdep_dev_register, .dev_disconnect = snd_hwdep_dev_disconnect, }; snd_assert(rhwdep != NULL, return -EINVAL); *rhwdep = NULL; snd_assert(card != NULL, return -ENXIO); hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); if (hwdep == NULL) { snd_printk(KERN_ERR "hwdep: cannot allocate\n"); return -ENOMEM; } hwdep->card = card; hwdep->device = device; if (id) strlcpy(hwdep->id, id, sizeof(hwdep->id)); #ifdef CONFIG_SND_OSSEMUL hwdep->oss_type = -1; #endif if ((err = snd_device_new(card, SNDRV_DEV_HWDEP, hwdep, &ops)) < 0) { snd_hwdep_free(hwdep); return err; } init_waitqueue_head(&hwdep->open_wait); mutex_init(&hwdep->open_mutex); *rhwdep = hwdep; return 0; }
static int snd_hwdep_dev_free(struct snd_device *device) { struct snd_hwdep *hwdep = device->device_data; return snd_hwdep_free(hwdep); }