Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: Introduce snd_card_create()

Introduced snd_card_create() function as a replacement of snd_card_new().
The new function returns a negative error code so that the probe callback
can return the proper error code, while snd_card_new() can give only NULL
check.

The old snd_card_new() is still provided as an inline function but with
__deprecated attribute. It'll be removed soon later.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Takashi Iwai and committed by
Takashi Iwai
53fb1e63 c5976504

+44 -17
+13 -1
include/sound/core.h
··· 296 296 extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd); 297 297 #endif 298 298 299 + int snd_card_create(int idx, const char *id, 300 + struct module *module, int extra_size, 301 + struct snd_card **card_ret); 302 + 303 + static inline __deprecated 299 304 struct snd_card *snd_card_new(int idx, const char *id, 300 - struct module *module, int extra_size); 305 + struct module *module, int extra_size) 306 + { 307 + struct snd_card *card; 308 + if (snd_card_create(idx, id, module, extra_size, &card) < 0) 309 + return NULL; 310 + return card; 311 + } 312 + 301 313 int snd_card_disconnect(struct snd_card *card); 302 314 int snd_card_free(struct snd_card *card); 303 315 int snd_card_free_when_closed(struct snd_card *card);
+31 -16
sound/core/init.c
··· 121 121 #endif 122 122 123 123 /** 124 - * snd_card_new - create and initialize a soundcard structure 124 + * snd_card_create - create and initialize a soundcard structure 125 125 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] 126 126 * @xid: card identification (ASCII string) 127 127 * @module: top level module for locking 128 128 * @extra_size: allocate this extra size after the main soundcard structure 129 + * @card_ret: the pointer to store the created card instance 129 130 * 130 131 * Creates and initializes a soundcard structure. 131 132 * 132 - * Returns kmallocated snd_card structure. Creates the ALSA control interface 133 - * (which is blocked until snd_card_register function is called). 133 + * The function allocates snd_card instance via kzalloc with the given 134 + * space for the driver to use freely. The allocated struct is stored 135 + * in the given card_ret pointer. 136 + * 137 + * Returns zero if successful or a negative error code. 134 138 */ 135 - struct snd_card *snd_card_new(int idx, const char *xid, 136 - struct module *module, int extra_size) 139 + int snd_card_create(int idx, const char *xid, 140 + struct module *module, int extra_size, 141 + struct snd_card **card_ret) 137 142 { 138 143 struct snd_card *card; 139 144 int err, idx2; 140 145 146 + if (snd_BUG_ON(!card_ret)) 147 + return -EINVAL; 148 + *card_ret = NULL; 149 + 141 150 if (extra_size < 0) 142 151 extra_size = 0; 143 152 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); 144 - if (card == NULL) 145 - return NULL; 153 + if (!card) 154 + return -ENOMEM; 146 155 if (xid) { 147 - if (!snd_info_check_reserved_words(xid)) 156 + if (!snd_info_check_reserved_words(xid)) { 157 + snd_printk(KERN_ERR 158 + "given id string '%s' is reserved.\n", xid); 159 + err = -EBUSY; 148 160 goto __error; 161 + } 149 162 strlcpy(card->id, xid, sizeof(card->id)); 150 163 } 151 164 err = 0; ··· 215 202 #endif 216 203 /* the control interface cannot be accessed from the user space until */ 217 204 /* snd_cards_bitmask and snd_cards are set with snd_card_register */ 218 - if ((err = snd_ctl_create(card)) < 0) { 219 - snd_printd("unable to register control minors\n"); 205 + err = snd_ctl_create(card); 206 + if (err < 0) { 207 + snd_printk(KERN_ERR "unable to register control minors\n"); 220 208 goto __error; 221 209 } 222 - if ((err = snd_info_card_create(card)) < 0) { 223 - snd_printd("unable to create card info\n"); 210 + err = snd_info_card_create(card); 211 + if (err < 0) { 212 + snd_printk(KERN_ERR "unable to create card info\n"); 224 213 goto __error_ctl; 225 214 } 226 215 if (extra_size > 0) 227 216 card->private_data = (char *)card + sizeof(struct snd_card); 228 - return card; 217 + *card_ret = card; 218 + return 0; 229 219 230 220 __error_ctl: 231 221 snd_device_free_all(card, SNDRV_DEV_CMD_PRE); 232 222 __error: 233 223 kfree(card); 234 - return NULL; 224 + return err; 235 225 } 236 - 237 - EXPORT_SYMBOL(snd_card_new); 226 + EXPORT_SYMBOL(snd_card_create); 238 227 239 228 /* return non-zero if a card is already locked */ 240 229 int snd_card_locked(int card)