aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-03-23 19:35:35 -0400
committerTakashi Iwai <tiwai@suse.de>2009-03-23 19:35:35 -0400
commitdec14f8c0eff54549e5747f8a4d1dc6c0347e2dd (patch)
treeaf1744c17c4bacad4c9524ad096d5a65f6c25c73 /sound/core
parent8e0ee43bc2c3e19db56a4adaa9a9b04ce885cd84 (diff)
parentb1a0aac05f044e78a589bfd7a9e2334aa640eb45 (diff)
Merge branch 'topic/snd_card_new-err' into for-linus
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/init.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/sound/core/init.c b/sound/core/init.c
index 0d5520c415d3..dc4b80c7f311 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -121,31 +121,44 @@ static inline int init_info_for_card(struct snd_card *card)
121#endif 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 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] 125 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
126 * @xid: card identification (ASCII string) 126 * @xid: card identification (ASCII string)
127 * @module: top level module for locking 127 * @module: top level module for locking
128 * @extra_size: allocate this extra size after the main soundcard structure 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 * Creates and initializes a soundcard structure. 131 * Creates and initializes a soundcard structure.
131 * 132 *
132 * Returns kmallocated snd_card structure. Creates the ALSA control interface 133 * The function allocates snd_card instance via kzalloc with the given
133 * (which is blocked until snd_card_register function is called). 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 */
135struct snd_card *snd_card_new(int idx, const char *xid, 139int snd_card_create(int idx, const char *xid,
136 struct module *module, int extra_size) 140 struct module *module, int extra_size,
141 struct snd_card **card_ret)
137{ 142{
138 struct snd_card *card; 143 struct snd_card *card;
139 int err, idx2; 144 int err, idx2;
140 145
146 if (snd_BUG_ON(!card_ret))
147 return -EINVAL;
148 *card_ret = NULL;
149
141 if (extra_size < 0) 150 if (extra_size < 0)
142 extra_size = 0; 151 extra_size = 0;
143 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); 152 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL);
144 if (card == NULL) 153 if (!card)
145 return NULL; 154 return -ENOMEM;
146 if (xid) { 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 goto __error; 160 goto __error;
161 }
149 strlcpy(card->id, xid, sizeof(card->id)); 162 strlcpy(card->id, xid, sizeof(card->id));
150 } 163 }
151 err = 0; 164 err = 0;
@@ -202,26 +215,28 @@ struct snd_card *snd_card_new(int idx, const char *xid,
202#endif 215#endif
203 /* the control interface cannot be accessed from the user space until */ 216 /* the control interface cannot be accessed from the user space until */
204 /* snd_cards_bitmask and snd_cards are set with snd_card_register */ 217 /* snd_cards_bitmask and snd_cards are set with snd_card_register */
205 if ((err = snd_ctl_create(card)) < 0) { 218 err = snd_ctl_create(card);
206 snd_printd("unable to register control minors\n"); 219 if (err < 0) {
220 snd_printk(KERN_ERR "unable to register control minors\n");
207 goto __error; 221 goto __error;
208 } 222 }
209 if ((err = snd_info_card_create(card)) < 0) { 223 err = snd_info_card_create(card);
210 snd_printd("unable to create card info\n"); 224 if (err < 0) {
225 snd_printk(KERN_ERR "unable to create card info\n");
211 goto __error_ctl; 226 goto __error_ctl;
212 } 227 }
213 if (extra_size > 0) 228 if (extra_size > 0)
214 card->private_data = (char *)card + sizeof(struct snd_card); 229 card->private_data = (char *)card + sizeof(struct snd_card);
215 return card; 230 *card_ret = card;
231 return 0;
216 232
217 __error_ctl: 233 __error_ctl:
218 snd_device_free_all(card, SNDRV_DEV_CMD_PRE); 234 snd_device_free_all(card, SNDRV_DEV_CMD_PRE);
219 __error: 235 __error:
220 kfree(card); 236 kfree(card);
221 return NULL; 237 return err;
222} 238}
223 239EXPORT_SYMBOL(snd_card_create);
224EXPORT_SYMBOL(snd_card_new);
225 240
226/* return non-zero if a card is already locked */ 241/* return non-zero if a card is already locked */
227int snd_card_locked(int card) 242int snd_card_locked(int card)