···121121#endif122122123123/**124124- * snd_card_new - create and initialize a soundcard structure124124+ * snd_card_create - create and initialize a soundcard structure125125 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]126126 * @xid: card identification (ASCII string)127127 * @module: top level module for locking128128 * @extra_size: allocate this extra size after the main soundcard structure129129+ * @card_ret: the pointer to store the created card instance129130 *130131 * Creates and initializes a soundcard structure.131132 *132132- * Returns kmallocated snd_card structure. Creates the ALSA control interface133133- * (which is blocked until snd_card_register function is called).133133+ * The function allocates snd_card instance via kzalloc with the given134134+ * space for the driver to use freely. The allocated struct is stored135135+ * in the given card_ret pointer.136136+ *137137+ * Returns zero if successful or a negative error code.134138 */135135-struct snd_card *snd_card_new(int idx, const char *xid,136136- struct module *module, int extra_size)139139+int snd_card_create(int idx, const char *xid,140140+ struct module *module, int extra_size,141141+ struct snd_card **card_ret)137142{138143 struct snd_card *card;139144 int err, idx2;140145146146+ if (snd_BUG_ON(!card_ret))147147+ return -EINVAL;148148+ *card_ret = NULL;149149+141150 if (extra_size < 0)142151 extra_size = 0;143152 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL);144144- if (card == NULL)145145- return NULL;153153+ if (!card)154154+ return -ENOMEM;146155 if (xid) {147147- if (!snd_info_check_reserved_words(xid))156156+ if (!snd_info_check_reserved_words(xid)) {157157+ snd_printk(KERN_ERR158158+ "given id string '%s' is reserved.\n", xid);159159+ err = -EBUSY;148160 goto __error;161161+ }149162 strlcpy(card->id, xid, sizeof(card->id));150163 }151164 err = 0;···215202#endif216203 /* the control interface cannot be accessed from the user space until */217204 /* snd_cards_bitmask and snd_cards are set with snd_card_register */218218- if ((err = snd_ctl_create(card)) < 0) {219219- snd_printd("unable to register control minors\n");205205+ err = snd_ctl_create(card);206206+ if (err < 0) {207207+ snd_printk(KERN_ERR "unable to register control minors\n");220208 goto __error;221209 }222222- if ((err = snd_info_card_create(card)) < 0) {223223- snd_printd("unable to create card info\n");210210+ err = snd_info_card_create(card);211211+ if (err < 0) {212212+ snd_printk(KERN_ERR "unable to create card info\n");224213 goto __error_ctl;225214 }226215 if (extra_size > 0)227216 card->private_data = (char *)card + sizeof(struct snd_card);228228- return card;217217+ *card_ret = card;218218+ return 0;229219230220 __error_ctl:231221 snd_device_free_all(card, SNDRV_DEV_CMD_PRE);232222 __error:233223 kfree(card);234234- return NULL;224224+ return err;235225}236236-237237-EXPORT_SYMBOL(snd_card_new);226226+EXPORT_SYMBOL(snd_card_create);238227239228/* return non-zero if a card is already locked */240229int snd_card_locked(int card)
+4-4
sound/drivers/dummy.c
···588588 int idx, err;589589 int dev = devptr->id;590590591591- card = snd_card_new(index[dev], id[dev], THIS_MODULE,592592- sizeof(struct snd_dummy));593593- if (card == NULL)594594- return -ENOMEM;591591+ err = snd_card_create(index[dev], id[dev], THIS_MODULE,592592+ sizeof(struct snd_dummy), &card);593593+ if (err < 0)594594+ return err;595595 dummy = card->private_data;596596 dummy->card = card;597597 for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {