ALSA: usb-audio: Avoid lowlevel device object

Simplify the device management by replacing the lowlevel device object
allocation with the card->private_data.  Nowadays there is almost no
advantage by the lowlevel device, and with card->private_data, the
code becomes cleaner.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2018-05-27 15:07:01 +02:00
parent f25ecf8f98
commit 011ae2bf06

View File

@ -342,8 +342,9 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
* *
*/ */
static int snd_usb_audio_free(struct snd_usb_audio *chip) static void snd_usb_audio_free(struct snd_card *card)
{ {
struct snd_usb_audio *chip = card->private_data;
struct snd_usb_endpoint *ep, *n; struct snd_usb_endpoint *ep, *n;
list_for_each_entry_safe(ep, n, &chip->ep_list, list) list_for_each_entry_safe(ep, n, &chip->ep_list, list)
@ -352,14 +353,6 @@ static int snd_usb_audio_free(struct snd_usb_audio *chip)
mutex_destroy(&chip->mutex); mutex_destroy(&chip->mutex);
if (!atomic_read(&chip->shutdown)) if (!atomic_read(&chip->shutdown))
dev_set_drvdata(&chip->dev->dev, NULL); dev_set_drvdata(&chip->dev->dev, NULL);
kfree(chip);
return 0;
}
static int snd_usb_audio_dev_free(struct snd_device *device)
{
struct snd_usb_audio *chip = device->device_data;
return snd_usb_audio_free(chip);
} }
static void usb_audio_make_shortname(struct usb_device *dev, static void usb_audio_make_shortname(struct usb_device *dev,
@ -459,9 +452,6 @@ static int snd_usb_audio_create(struct usb_interface *intf,
struct snd_usb_audio *chip; struct snd_usb_audio *chip;
int err; int err;
char component[14]; char component[14];
static struct snd_device_ops ops = {
.dev_free = snd_usb_audio_dev_free,
};
*rchip = NULL; *rchip = NULL;
@ -479,18 +469,13 @@ static int snd_usb_audio_create(struct usb_interface *intf,
} }
err = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE, err = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE,
0, &card); sizeof(*chip), &card);
if (err < 0) { if (err < 0) {
dev_err(&dev->dev, "cannot create card instance %d\n", idx); dev_err(&dev->dev, "cannot create card instance %d\n", idx);
return err; return err;
} }
chip = kzalloc(sizeof(*chip), GFP_KERNEL); chip = card->private_data;
if (! chip) {
snd_card_free(card);
return -ENOMEM;
}
mutex_init(&chip->mutex); mutex_init(&chip->mutex);
init_waitqueue_head(&chip->shutdown_wait); init_waitqueue_head(&chip->shutdown_wait);
chip->index = idx; chip->index = idx;
@ -508,12 +493,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,
INIT_LIST_HEAD(&chip->midi_list); INIT_LIST_HEAD(&chip->midi_list);
INIT_LIST_HEAD(&chip->mixer_list); INIT_LIST_HEAD(&chip->mixer_list);
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); card->private_free = snd_usb_audio_free;
if (err < 0) {
snd_usb_audio_free(chip);
snd_card_free(card);
return err;
}
strcpy(card->driver, "USB-Audio"); strcpy(card->driver, "USB-Audio");
sprintf(component, "USB%04x:%04x", sprintf(component, "USB%04x:%04x",