Commit 4c8c3a4f authored by Takashi Iwai's avatar Takashi Iwai

ALSA: usb-audio: Flatten probe and disconnect functions

The usb-audio probe and disconnect functions have been split just for
adapting the (new!) API at 2.5 kernel time.  We left them until now,
partly because we wanted to build with the pretty old kernels in the
external alsa-driver tree.  But the support of such old kernels has
been longly stopped, so it's good time to clean up this mess.

One good point by this cleanup is that now the probe function returns
a proper error code instead of only -EIO.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 2603fe21
...@@ -112,7 +112,7 @@ static struct usb_driver usb_audio_driver; ...@@ -112,7 +112,7 @@ static struct usb_driver usb_audio_driver;
/* /*
* disconnect streams * disconnect streams
* called from snd_usb_audio_disconnect() * called from usb_audio_disconnect()
*/ */
static void snd_usb_stream_disconnect(struct list_head *head) static void snd_usb_stream_disconnect(struct list_head *head)
{ {
...@@ -475,14 +475,14 @@ static int snd_usb_audio_create(struct usb_interface *intf, ...@@ -475,14 +475,14 @@ static int snd_usb_audio_create(struct usb_interface *intf,
* only at the first time. the successive calls of this function will * only at the first time. the successive calls of this function will
* append the pcm interface to the corresponding card. * append the pcm interface to the corresponding card.
*/ */
static struct snd_usb_audio * static int usb_audio_probe(struct usb_interface *intf,
snd_usb_audio_probe(struct usb_device *dev, const struct usb_device_id *usb_id)
struct usb_interface *intf,
const struct usb_device_id *usb_id)
{ {
const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info; struct usb_device *dev = interface_to_usbdev(intf);
int i, err; const struct snd_usb_audio_quirk *quirk =
(const struct snd_usb_audio_quirk *)usb_id->driver_info;
struct snd_usb_audio *chip; struct snd_usb_audio *chip;
int i, err;
struct usb_host_interface *alts; struct usb_host_interface *alts;
int ifnum; int ifnum;
u32 id; u32 id;
...@@ -492,10 +492,11 @@ snd_usb_audio_probe(struct usb_device *dev, ...@@ -492,10 +492,11 @@ snd_usb_audio_probe(struct usb_device *dev,
id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
le16_to_cpu(dev->descriptor.idProduct)); le16_to_cpu(dev->descriptor.idProduct));
if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
goto __err_val; return -ENXIO;
if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0) err = snd_usb_apply_boot_quirk(dev, intf, quirk);
goto __err_val; if (err < 0)
return err;
/* /*
* found a config. now register to ALSA * found a config. now register to ALSA
...@@ -508,6 +509,7 @@ snd_usb_audio_probe(struct usb_device *dev, ...@@ -508,6 +509,7 @@ snd_usb_audio_probe(struct usb_device *dev,
if (usb_chip[i] && usb_chip[i]->dev == dev) { if (usb_chip[i] && usb_chip[i]->dev == dev) {
if (usb_chip[i]->shutdown) { if (usb_chip[i]->shutdown) {
dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n"); dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n");
err = -EIO;
goto __error; goto __error;
} }
chip = usb_chip[i]; chip = usb_chip[i];
...@@ -523,15 +525,16 @@ snd_usb_audio_probe(struct usb_device *dev, ...@@ -523,15 +525,16 @@ snd_usb_audio_probe(struct usb_device *dev,
if (enable[i] && ! usb_chip[i] && if (enable[i] && ! usb_chip[i] &&
(vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) && (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
(pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) { (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
if (snd_usb_audio_create(intf, dev, i, quirk, err = snd_usb_audio_create(intf, dev, i, quirk,
&chip) < 0) { &chip);
if (err < 0)
goto __error; goto __error;
}
chip->pm_intf = intf; chip->pm_intf = intf;
break; break;
} }
if (!chip) { if (!chip) {
dev_err(&dev->dev, "no available usb audio device\n"); dev_err(&dev->dev, "no available usb audio device\n");
err = -ENODEV;
goto __error; goto __error;
} }
} }
...@@ -548,28 +551,32 @@ snd_usb_audio_probe(struct usb_device *dev, ...@@ -548,28 +551,32 @@ snd_usb_audio_probe(struct usb_device *dev,
err = 1; /* continue */ err = 1; /* continue */
if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
/* need some special handlings */ /* need some special handlings */
if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0) err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk);
if (err < 0)
goto __error; goto __error;
} }
if (err > 0) { if (err > 0) {
/* create normal USB audio interfaces */ /* create normal USB audio interfaces */
if (snd_usb_create_streams(chip, ifnum) < 0 || err = snd_usb_create_streams(chip, ifnum);
snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) { if (err < 0)
goto __error;
err = snd_usb_create_mixer(chip, ifnum, ignore_ctl_error);
if (err < 0)
goto __error; goto __error;
}
} }
/* we are allowed to call snd_card_register() many times */ /* we are allowed to call snd_card_register() many times */
if (snd_card_register(chip->card) < 0) { err = snd_card_register(chip->card);
if (err < 0)
goto __error; goto __error;
}
usb_chip[chip->index] = chip; usb_chip[chip->index] = chip;
chip->num_interfaces++; chip->num_interfaces++;
chip->probing = 0; chip->probing = 0;
usb_set_intfdata(intf, chip);
mutex_unlock(&register_mutex); mutex_unlock(&register_mutex);
return chip; return 0;
__error: __error:
if (chip) { if (chip) {
...@@ -578,17 +585,16 @@ snd_usb_audio_probe(struct usb_device *dev, ...@@ -578,17 +585,16 @@ snd_usb_audio_probe(struct usb_device *dev,
chip->probing = 0; chip->probing = 0;
} }
mutex_unlock(&register_mutex); mutex_unlock(&register_mutex);
__err_val: return err;
return NULL;
} }
/* /*
* we need to take care of counter, since disconnection can be called also * we need to take care of counter, since disconnection can be called also
* many times as well as usb_audio_probe(). * many times as well as usb_audio_probe().
*/ */
static void snd_usb_audio_disconnect(struct usb_device *dev, static void usb_audio_disconnect(struct usb_interface *intf)
struct snd_usb_audio *chip)
{ {
struct snd_usb_audio *chip = usb_get_intfdata(intf);
struct snd_card *card; struct snd_card *card;
struct list_head *p; struct list_head *p;
...@@ -630,27 +636,6 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, ...@@ -630,27 +636,6 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
} }
} }
/*
* new 2.5 USB kernel API
*/
static int usb_audio_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct snd_usb_audio *chip;
chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
if (chip) {
usb_set_intfdata(intf, chip);
return 0;
} else
return -EIO;
}
static void usb_audio_disconnect(struct usb_interface *intf)
{
snd_usb_audio_disconnect(interface_to_usbdev(intf),
usb_get_intfdata(intf));
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
int snd_usb_autoresume(struct snd_usb_audio *chip) int snd_usb_autoresume(struct snd_usb_audio *chip)
......
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