diff options
author | Takashi Iwai <tiwai@alsa3.local> | 2008-12-28 10:32:08 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-01-12 08:56:41 -0500 |
commit | 53fb1e63599438bd5f6fbb852023d80916d83983 (patch) | |
tree | 9fdf278a517805b11a977ce69ffbf61298ba0aac /sound/core | |
parent | c59765042f53a79a7a65585042ff463b69cb248c (diff) |
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>
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/init.c | 47 |
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 | */ |
135 | struct snd_card *snd_card_new(int idx, const char *xid, | 139 | int 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 | 239 | EXPORT_SYMBOL(snd_card_create); | |
224 | EXPORT_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 */ |
227 | int snd_card_locked(int card) | 242 | int snd_card_locked(int card) |