Commit 51721f70 authored by Takashi Iwai's avatar Takashi Iwai Committed by Takashi Iwai

ALSA: Return proper error code at probe in sound/usb/*

Some drivers in soudn/usb/* don't handle the error code properly
from snd_card_create().  This patch fixes these places.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 3e7fb9f7
...@@ -336,7 +336,7 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev) ...@@ -336,7 +336,7 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
log("Unable to set up control system (ret=%d)\n", ret); log("Unable to set up control system (ret=%d)\n", ret);
} }
static struct snd_card* create_card(struct usb_device* usb_dev) static int create_card(struct usb_device* usb_dev, struct snd_card **cardp)
{ {
int devnum; int devnum;
int err; int err;
...@@ -348,12 +348,12 @@ static struct snd_card* create_card(struct usb_device* usb_dev) ...@@ -348,12 +348,12 @@ static struct snd_card* create_card(struct usb_device* usb_dev)
break; break;
if (devnum >= SNDRV_CARDS) if (devnum >= SNDRV_CARDS)
return NULL; return -ENODEV;
err = snd_card_create(index[devnum], id[devnum], THIS_MODULE, err = snd_card_create(index[devnum], id[devnum], THIS_MODULE,
sizeof(struct snd_usb_caiaqdev), &card); sizeof(struct snd_usb_caiaqdev), &card);
if (err < 0) if (err < 0)
return NULL; return err;
dev = caiaqdev(card); dev = caiaqdev(card);
dev->chip.dev = usb_dev; dev->chip.dev = usb_dev;
...@@ -363,7 +363,8 @@ static struct snd_card* create_card(struct usb_device* usb_dev) ...@@ -363,7 +363,8 @@ static struct snd_card* create_card(struct usb_device* usb_dev)
spin_lock_init(&dev->spinlock); spin_lock_init(&dev->spinlock);
snd_card_set_dev(card, &usb_dev->dev); snd_card_set_dev(card, &usb_dev->dev);
return card; *cardp = card;
return 0;
} }
static int __devinit init_card(struct snd_usb_caiaqdev *dev) static int __devinit init_card(struct snd_usb_caiaqdev *dev)
...@@ -442,10 +443,10 @@ static int __devinit snd_probe(struct usb_interface *intf, ...@@ -442,10 +443,10 @@ static int __devinit snd_probe(struct usb_interface *intf,
struct snd_card *card; struct snd_card *card;
struct usb_device *device = interface_to_usbdev(intf); struct usb_device *device = interface_to_usbdev(intf);
card = create_card(device); ret = create_card(device, &card);
if (!card) if (ret < 0)
return -ENOMEM; return ret;
usb_set_intfdata(intf, card); usb_set_intfdata(intf, card);
ret = init_card(caiaqdev(card)); ret = init_card(caiaqdev(card));
......
...@@ -478,7 +478,7 @@ static bool us122l_create_card(struct snd_card *card) ...@@ -478,7 +478,7 @@ static bool us122l_create_card(struct snd_card *card)
return true; return true;
} }
static struct snd_card *usx2y_create_card(struct usb_device *device) static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
{ {
int dev; int dev;
struct snd_card *card; struct snd_card *card;
...@@ -488,11 +488,11 @@ static struct snd_card *usx2y_create_card(struct usb_device *device) ...@@ -488,11 +488,11 @@ static struct snd_card *usx2y_create_card(struct usb_device *device)
if (enable[dev] && !snd_us122l_card_used[dev]) if (enable[dev] && !snd_us122l_card_used[dev])
break; break;
if (dev >= SNDRV_CARDS) if (dev >= SNDRV_CARDS)
return NULL; return -ENODEV;
err = snd_card_create(index[dev], id[dev], THIS_MODULE, err = snd_card_create(index[dev], id[dev], THIS_MODULE,
sizeof(struct us122l), &card); sizeof(struct us122l), &card);
if (err < 0) if (err < 0)
return NULL; return err;
snd_us122l_card_used[US122L(card)->chip.index = dev] = 1; snd_us122l_card_used[US122L(card)->chip.index = dev] = 1;
US122L(card)->chip.dev = device; US122L(card)->chip.dev = device;
...@@ -511,46 +511,57 @@ static struct snd_card *usx2y_create_card(struct usb_device *device) ...@@ -511,46 +511,57 @@ static struct snd_card *usx2y_create_card(struct usb_device *device)
US122L(card)->chip.dev->devnum US122L(card)->chip.dev->devnum
); );
snd_card_set_dev(card, &device->dev); snd_card_set_dev(card, &device->dev);
return card; *cardp = card;
return 0;
} }
static void *us122l_usb_probe(struct usb_interface *intf, static int us122l_usb_probe(struct usb_interface *intf,
const struct usb_device_id *device_id) const struct usb_device_id *device_id,
struct snd_card **cardp)
{ {
struct usb_device *device = interface_to_usbdev(intf); struct usb_device *device = interface_to_usbdev(intf);
struct snd_card *card = usx2y_create_card(device); struct snd_card *card;
int err;
if (!card) err = usx2y_create_card(device, &card);
return NULL; if (err < 0)
return err;
if (!us122l_create_card(card) || if (!us122l_create_card(card)) {
snd_card_register(card) < 0) {
snd_card_free(card); snd_card_free(card);
return NULL; return -EINVAL;
}
err = snd_card_register(card);
if (err < 0) {
snd_card_free(card);
return err;
} }
usb_get_dev(device); usb_get_dev(device);
return card; *cardp = card;
return 0;
} }
static int snd_us122l_probe(struct usb_interface *intf, static int snd_us122l_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct snd_card *card; struct snd_card *card;
int err;
snd_printdd(KERN_DEBUG"%p:%i\n", snd_printdd(KERN_DEBUG"%p:%i\n",
intf, intf->cur_altsetting->desc.bInterfaceNumber); intf, intf->cur_altsetting->desc.bInterfaceNumber);
if (intf->cur_altsetting->desc.bInterfaceNumber != 1) if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
return 0; return 0;
card = us122l_usb_probe(usb_get_intf(intf), id); err = us122l_usb_probe(usb_get_intf(intf), id, &card);
if (err < 0) {
if (card) { usb_put_intf(intf);
usb_set_intfdata(intf, card); return err;
return 0;
} }
usb_put_intf(intf); usb_set_intfdata(intf, card);
return -EIO; return 0;
} }
static void snd_us122l_disconnect(struct usb_interface *intf) static void snd_us122l_disconnect(struct usb_interface *intf)
......
...@@ -333,7 +333,7 @@ static struct usb_device_id snd_usX2Y_usb_id_table[] = { ...@@ -333,7 +333,7 @@ static struct usb_device_id snd_usX2Y_usb_id_table[] = {
{ /* terminator */ } { /* terminator */ }
}; };
static struct snd_card *usX2Y_create_card(struct usb_device *device) static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
{ {
int dev; int dev;
struct snd_card * card; struct snd_card * card;
...@@ -343,11 +343,11 @@ static struct snd_card *usX2Y_create_card(struct usb_device *device) ...@@ -343,11 +343,11 @@ static struct snd_card *usX2Y_create_card(struct usb_device *device)
if (enable[dev] && !snd_usX2Y_card_used[dev]) if (enable[dev] && !snd_usX2Y_card_used[dev])
break; break;
if (dev >= SNDRV_CARDS) if (dev >= SNDRV_CARDS)
return NULL; return -ENODEV;
err = snd_card_create(index[dev], id[dev], THIS_MODULE, err = snd_card_create(index[dev], id[dev], THIS_MODULE,
sizeof(struct usX2Ydev), &card); sizeof(struct usX2Ydev), &card);
if (err < 0) if (err < 0)
return NULL; return err;
snd_usX2Y_card_used[usX2Y(card)->chip.index = dev] = 1; snd_usX2Y_card_used[usX2Y(card)->chip.index = dev] = 1;
card->private_free = snd_usX2Y_card_private_free; card->private_free = snd_usX2Y_card_private_free;
usX2Y(card)->chip.dev = device; usX2Y(card)->chip.dev = device;
...@@ -365,26 +365,36 @@ static struct snd_card *usX2Y_create_card(struct usb_device *device) ...@@ -365,26 +365,36 @@ static struct snd_card *usX2Y_create_card(struct usb_device *device)
usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum
); );
snd_card_set_dev(card, &device->dev); snd_card_set_dev(card, &device->dev);
return card; *cardp = card;
return 0;
} }
static void *usX2Y_usb_probe(struct usb_device *device, struct usb_interface *intf, const struct usb_device_id *device_id) static int usX2Y_usb_probe(struct usb_device *device,
struct usb_interface *intf,
const struct usb_device_id *device_id,
struct snd_card **cardp)
{ {
int err; int err;
struct snd_card * card; struct snd_card * card;
*cardp = NULL;
if (le16_to_cpu(device->descriptor.idVendor) != 0x1604 || if (le16_to_cpu(device->descriptor.idVendor) != 0x1604 ||
(le16_to_cpu(device->descriptor.idProduct) != USB_ID_US122 && (le16_to_cpu(device->descriptor.idProduct) != USB_ID_US122 &&
le16_to_cpu(device->descriptor.idProduct) != USB_ID_US224 && le16_to_cpu(device->descriptor.idProduct) != USB_ID_US224 &&
le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428) || le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428))
!(card = usX2Y_create_card(device))) return -EINVAL;
return NULL;
err = usX2Y_create_card(device, &card);
if (err < 0)
return err;
if ((err = usX2Y_hwdep_new(card, device)) < 0 || if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
(err = snd_card_register(card)) < 0) { (err = snd_card_register(card)) < 0) {
snd_card_free(card); snd_card_free(card);
return NULL; return err;
} }
return card; *cardp = card;
return 0;
} }
/* /*
...@@ -392,13 +402,14 @@ static void *usX2Y_usb_probe(struct usb_device *device, struct usb_interface *in ...@@ -392,13 +402,14 @@ static void *usX2Y_usb_probe(struct usb_device *device, struct usb_interface *in
*/ */
static int snd_usX2Y_probe(struct usb_interface *intf, const struct usb_device_id *id) static int snd_usX2Y_probe(struct usb_interface *intf, const struct usb_device_id *id)
{ {
void *chip; struct snd_card *card;
chip = usX2Y_usb_probe(interface_to_usbdev(intf), intf, id); int err;
if (chip) {
usb_set_intfdata(intf, chip); err = usX2Y_usb_probe(interface_to_usbdev(intf), intf, id, &card);
return 0; if (err < 0)
} else return err;
return -EIO; dev_set_drvdata(&intf->dev, card);
return 0;
} }
static void snd_usX2Y_disconnect(struct usb_interface *intf) static void snd_usX2Y_disconnect(struct usb_interface *intf)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment