Skip to content

Commit

Permalink
Merge branch 'topic/snd_card_new-err' into for-linus
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwai committed Mar 23, 2009
2 parents 8e0ee43 + b1a0aac commit dec14f8
Show file tree
Hide file tree
Showing 111 changed files with 617 additions and 516 deletions.
44 changes: 25 additions & 19 deletions Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@
}

/* (2) */
card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
if (card == NULL)
return -ENOMEM;
err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
if (err < 0)
return err;

/* (3) */
err = snd_mychip_create(card, pci, &chip);
Expand Down Expand Up @@ -590,8 +590,9 @@
<programlisting>
<![CDATA[
struct snd_card *card;
int err;
....
card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
]]>
</programlisting>
</informalexample>
Expand Down Expand Up @@ -809,26 +810,28 @@

<para>
As mentioned above, to create a card instance, call
<function>snd_card_new()</function>.
<function>snd_card_create()</function>.

<informalexample>
<programlisting>
<![CDATA[
struct snd_card *card;
card = snd_card_new(index, id, module, extra_size);
int err;
err = snd_card_create(index, id, module, extra_size, &card);
]]>
</programlisting>
</informalexample>
</para>

<para>
The function takes four arguments, the card-index number, the
The function takes five arguments, the card-index number, the
id string, the module pointer (usually
<constant>THIS_MODULE</constant>),
and the size of extra-data space. The last argument is used to
the size of extra-data space, and the pointer to return the
card instance. The extra_size argument is used to
allocate card-&gt;private_data for the
chip-specific data. Note that these data
are allocated by <function>snd_card_new()</function>.
are allocated by <function>snd_card_create()</function>.
</para>
</section>

Expand Down Expand Up @@ -915,15 +918,16 @@
</para>

<section id="card-management-chip-specific-snd-card-new">
<title>1. Allocating via <function>snd_card_new()</function>.</title>
<title>1. Allocating via <function>snd_card_create()</function>.</title>
<para>
As mentioned above, you can pass the extra-data-length
to the 4th argument of <function>snd_card_new()</function>, i.e.
to the 4th argument of <function>snd_card_create()</function>, i.e.

<informalexample>
<programlisting>
<![CDATA[
card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct mychip));
err = snd_card_create(index[dev], id[dev], THIS_MODULE,
sizeof(struct mychip), &card);
]]>
</programlisting>
</informalexample>
Expand Down Expand Up @@ -952,16 +956,16 @@

<para>
After allocating a card instance via
<function>snd_card_new()</function> (with
<constant>NULL</constant> on the 4th arg), call
<function>snd_card_create()</function> (with
<constant>0</constant> on the 4th arg), call
<function>kzalloc()</function>.

<informalexample>
<programlisting>
<![CDATA[
struct snd_card *card;
struct mychip *chip;
card = snd_card_new(index[dev], id[dev], THIS_MODULE, NULL);
err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
.....
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
]]>
Expand Down Expand Up @@ -5750,8 +5754,9 @@ struct _snd_pcm_runtime {
....
struct snd_card *card;
struct mychip *chip;
int err;
....
card = snd_card_new(index[dev], id[dev], THIS_MODULE, NULL);
err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
....
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
....
Expand All @@ -5763,7 +5768,7 @@ struct _snd_pcm_runtime {
</informalexample>

When you created the chip data with
<function>snd_card_new()</function>, it's anyway accessible
<function>snd_card_create()</function>, it's anyway accessible
via <structfield>private_data</structfield> field.

<informalexample>
Expand All @@ -5775,9 +5780,10 @@ struct _snd_pcm_runtime {
....
struct snd_card *card;
struct mychip *chip;
int err;
....
card = snd_card_new(index[dev], id[dev], THIS_MODULE,
sizeof(struct mychip));
err = snd_card_create(index[dev], id[dev], THIS_MODULE,
sizeof(struct mychip), &card);
....
chip = card->private_data;
....
Expand Down
7 changes: 4 additions & 3 deletions drivers/media/video/cx88/cx88-alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,10 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
return (-ENOENT);
}

card = snd_card_new(index[devno], id[devno], THIS_MODULE, sizeof(snd_cx88_card_t));
if (!card)
return (-ENOMEM);
err = snd_card_create(index[devno], id[devno], THIS_MODULE,
sizeof(snd_cx88_card_t), &card);
if (err < 0)
return err;

card->private_free = snd_cx88_dev_free;

Expand Down
7 changes: 4 additions & 3 deletions drivers/media/video/em28xx/em28xx-audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,10 @@ static int em28xx_audio_init(struct em28xx *dev)
printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
"Rechberger\n");

card = snd_card_new(index[devnr], "Em28xx Audio", THIS_MODULE, 0);
if (card == NULL)
return -ENOMEM;
err = snd_card_create(index[devnr], "Em28xx Audio", THIS_MODULE, 0,
&card);
if (err < 0)
return err;

spin_lock_init(&adev->slock);
err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
Expand Down
8 changes: 4 additions & 4 deletions drivers/media/video/saa7134/saa7134-alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,10 +990,10 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
if (!enable[devnum])
return -ENODEV;

card = snd_card_new(index[devnum], id[devnum], THIS_MODULE, sizeof(snd_card_saa7134_t));

if (card == NULL)
return -ENOMEM;
err = snd_card_create(index[devnum], id[devnum], THIS_MODULE,
sizeof(snd_card_saa7134_t), &card);
if (err < 0)
return err;

strcpy(card->driver, "SAA7134");

Expand Down
7 changes: 4 additions & 3 deletions drivers/staging/go7007/snd-go7007.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,11 @@ int go7007_snd_init(struct go7007 *go)
spin_lock_init(&gosnd->lock);
gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0;
gosnd->capturing = 0;
gosnd->card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
if (gosnd->card == NULL) {
ret = snd_card_create(index[dev], id[dev], THIS_MODULE, 0,
&gosnd->card);
if (ret < 0) {
kfree(gosnd);
return -ENOMEM;
return ret;
}
ret = snd_device_new(gosnd->card, SNDRV_DEV_LOWLEVEL, go,
&go7007_snd_device_ops);
Expand Down
7 changes: 3 additions & 4 deletions drivers/usb/gadget/gmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,9 @@ static int gmidi_register_card(struct gmidi_device *dev)
.dev_free = gmidi_snd_free,
};

card = snd_card_new(index, id, THIS_MODULE, 0);
if (!card) {
ERROR(dev, "snd_card_new failed\n");
err = -ENOMEM;
err = snd_card_create(index, id, THIS_MODULE, 0, &card);
if (err < 0) {
ERROR(dev, "snd_card_create failed\n");
goto fail;
}
dev->card = card;
Expand Down
14 changes: 13 additions & 1 deletion include/sound/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,20 @@ int snd_card_locked(int card);
extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
#endif

int snd_card_create(int idx, const char *id,
struct module *module, int extra_size,
struct snd_card **card_ret);

static inline __deprecated
struct snd_card *snd_card_new(int idx, const char *id,
struct module *module, int extra_size);
struct module *module, int extra_size)
{
struct snd_card *card;
if (snd_card_create(idx, id, module, extra_size, &card) < 0)
return NULL;
return card;
}

int snd_card_disconnect(struct snd_card *card);
int snd_card_free(struct snd_card *card);
int snd_card_free_when_closed(struct snd_card *card);
Expand Down
7 changes: 4 additions & 3 deletions sound/aoa/core/alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ int aoa_alsa_init(char *name, struct module *mod, struct device *dev)
/* cannot be EEXIST due to usage in aoa_fabric_register */
return -EBUSY;

alsa_card = snd_card_new(index, name, mod, sizeof(struct aoa_card));
if (!alsa_card)
return -ENOMEM;
err = snd_card_create(index, name, mod, sizeof(struct aoa_card),
&alsa_card);
if (err < 0)
return err;
aoa_card = alsa_card->private_data;
aoa_card->alsa_card = alsa_card;
alsa_card->dev = dev;
Expand Down
7 changes: 4 additions & 3 deletions sound/arm/aaci.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,11 @@ static struct aaci * __devinit aaci_init_card(struct amba_device *dev)
{
struct aaci *aaci;
struct snd_card *card;
int err;

card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
THIS_MODULE, sizeof(struct aaci));
if (card == NULL)
err = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
THIS_MODULE, sizeof(struct aaci), &card);
if (err < 0)
return NULL;

card->private_free = aaci_free_card;
Expand Down
7 changes: 3 additions & 4 deletions sound/arm/pxa2xx-ac97.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
struct snd_ac97_template ac97_template;
int ret;

ret = -ENOMEM;
card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
THIS_MODULE, 0);
if (!card)
ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
THIS_MODULE, 0, &card);
if (ret < 0)
goto err;

card->dev = &dev->dev;
Expand Down
7 changes: 4 additions & 3 deletions sound/arm/sa11xx-uda1341.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,10 @@ static int __devinit sa11xx_uda1341_probe(struct platform_device *devptr)
struct sa11xx_uda1341 *chip;

/* register the soundcard */
card = snd_card_new(-1, id, THIS_MODULE, sizeof(struct sa11xx_uda1341));
if (card == NULL)
return -ENOMEM;
err = snd_card_create(-1, id, THIS_MODULE,
sizeof(struct sa11xx_uda1341), &card);
if (err < 0)
return err;

chip = card->private_data;
spin_lock_init(&chip->s[0].dma_lock);
Expand Down
47 changes: 31 additions & 16 deletions sound/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,44 @@ static inline int init_info_for_card(struct snd_card *card)
#endif

/**
* snd_card_new - create and initialize a soundcard structure
* snd_card_create - create and initialize a soundcard structure
* @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
* @xid: card identification (ASCII string)
* @module: top level module for locking
* @extra_size: allocate this extra size after the main soundcard structure
* @card_ret: the pointer to store the created card instance
*
* Creates and initializes a soundcard structure.
*
* Returns kmallocated snd_card structure. Creates the ALSA control interface
* (which is blocked until snd_card_register function is called).
* The function allocates snd_card instance via kzalloc with the given
* space for the driver to use freely. The allocated struct is stored
* in the given card_ret pointer.
*
* Returns zero if successful or a negative error code.
*/
struct snd_card *snd_card_new(int idx, const char *xid,
struct module *module, int extra_size)
int snd_card_create(int idx, const char *xid,
struct module *module, int extra_size,
struct snd_card **card_ret)
{
struct snd_card *card;
int err, idx2;

if (snd_BUG_ON(!card_ret))
return -EINVAL;
*card_ret = NULL;

if (extra_size < 0)
extra_size = 0;
card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL);
if (card == NULL)
return NULL;
if (!card)
return -ENOMEM;
if (xid) {
if (!snd_info_check_reserved_words(xid))
if (!snd_info_check_reserved_words(xid)) {
snd_printk(KERN_ERR
"given id string '%s' is reserved.\n", xid);
err = -EBUSY;
goto __error;
}
strlcpy(card->id, xid, sizeof(card->id));
}
err = 0;
Expand Down Expand Up @@ -202,26 +215,28 @@ struct snd_card *snd_card_new(int idx, const char *xid,
#endif
/* the control interface cannot be accessed from the user space until */
/* snd_cards_bitmask and snd_cards are set with snd_card_register */
if ((err = snd_ctl_create(card)) < 0) {
snd_printd("unable to register control minors\n");
err = snd_ctl_create(card);
if (err < 0) {
snd_printk(KERN_ERR "unable to register control minors\n");
goto __error;
}
if ((err = snd_info_card_create(card)) < 0) {
snd_printd("unable to create card info\n");
err = snd_info_card_create(card);
if (err < 0) {
snd_printk(KERN_ERR "unable to create card info\n");
goto __error_ctl;
}
if (extra_size > 0)
card->private_data = (char *)card + sizeof(struct snd_card);
return card;
*card_ret = card;
return 0;

__error_ctl:
snd_device_free_all(card, SNDRV_DEV_CMD_PRE);
__error:
kfree(card);
return NULL;
return err;
}

EXPORT_SYMBOL(snd_card_new);
EXPORT_SYMBOL(snd_card_create);

/* return non-zero if a card is already locked */
int snd_card_locked(int card)
Expand Down
8 changes: 4 additions & 4 deletions sound/drivers/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ static int __devinit snd_dummy_probe(struct platform_device *devptr)
int idx, err;
int dev = devptr->id;

card = snd_card_new(index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_dummy));
if (card == NULL)
return -ENOMEM;
err = snd_card_create(index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_dummy), &card);
if (err < 0)
return err;
dummy = card->private_data;
dummy->card = card;
for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
Expand Down
6 changes: 3 additions & 3 deletions sound/drivers/ml403-ac97cr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,9 @@ static int __devinit snd_ml403_ac97cr_probe(struct platform_device *pfdev)
if (!enable[dev])
return -ENOENT;

card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
if (card == NULL)
return -ENOMEM;
err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
if (err < 0)
return err;
err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr);
if (err < 0) {
PDEBUG(INIT_FAILURE, "probe(): create failed!\n");
Expand Down
Loading

0 comments on commit dec14f8

Please sign in to comment.