Skip to content

Commit

Permalink
ALSA: usb-audio: Replace probing flag with active refcount
Browse files Browse the repository at this point in the history
We can use active refcount for preventing autopm during probe.

Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Aug 26, 2015
1 parent 47ab154 commit a6da499
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
12 changes: 4 additions & 8 deletions sound/usb/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,
chip->card = card;
chip->setup = device_setup[idx];
chip->autoclock = autoclock;
chip->probing = 1;
atomic_set(&chip->active, 1); /* avoid autopm during probing */
atomic_set(&chip->usage_count, 0);
atomic_set(&chip->shutdown, 0);

Expand Down Expand Up @@ -503,7 +503,7 @@ static int usb_audio_probe(struct usb_interface *intf,
goto __error;
}
chip = usb_chip[i];
chip->probing = 1;
atomic_inc(&chip->active); /* avoid autopm */
break;
}
}
Expand Down Expand Up @@ -563,16 +563,16 @@ static int usb_audio_probe(struct usb_interface *intf,

usb_chip[chip->index] = chip;
chip->num_interfaces++;
chip->probing = 0;
usb_set_intfdata(intf, chip);
atomic_dec(&chip->active);
mutex_unlock(&register_mutex);
return 0;

__error:
if (chip) {
if (!chip->num_interfaces)
snd_card_free(chip->card);
chip->probing = 0;
atomic_dec(&chip->active);
}
mutex_unlock(&register_mutex);
return err;
Expand Down Expand Up @@ -668,17 +668,13 @@ int snd_usb_autoresume(struct snd_usb_audio *chip)
{
if (atomic_read(&chip->shutdown))
return -EIO;
if (chip->probing)
return 0;
if (atomic_inc_return(&chip->active) == 1)
return usb_autopm_get_interface(chip->pm_intf);
return 0;
}

void snd_usb_autosuspend(struct snd_usb_audio *chip)
{
if (chip->probing)
return;
if (atomic_dec_and_test(&chip->active))
usb_autopm_put_interface(chip->pm_intf);
}
Expand Down
1 change: 0 additions & 1 deletion sound/usb/usbaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct snd_usb_audio {
struct usb_interface *pm_intf;
u32 usb_id;
struct mutex mutex;
unsigned int probing:1;
unsigned int autosuspended:1;
atomic_t active;
atomic_t shutdown;
Expand Down

0 comments on commit a6da499

Please sign in to comment.