All of lore.kernel.org
 help / color / mirror / Atom feed
* A portion of USB Headsets loses previous sound volume setting after a suspend resume
@ 2021-09-09 10:21 En-Shuo Hsu
  2021-09-09 13:30 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: En-Shuo Hsu @ 2021-09-09 10:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: tiwai, Yu-Hsuan Hsu

Hi

We recently found that some USB headsets may fall back to their full volume
after a suspend and resume. We think the issue is caused by the logic of
mixer_ctl_feature_put
<https://github.com/torvalds/linux/blob/a3fa7a101dcff93791d1b1bdb3affcad1410c8c1/sound/usb/mixer.c#L1396>
in
sound/usb/mixer.c:

err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
if (err < 0)
  return filter_error(cval, err);
  val = ucontrol->value.integer.value[cnt];
  val = get_abs_value(cval, val);
if (oval != val) {
  snd_usb_set_cur_mix_value(cval, c + 1, cnt, val);
  changed = 1;
}

The existing codes get the existing mixer control value and ignore the set
if the val doesn't change. However, in the suspend and resume case, the USB
headset's control value is actually changed.

Removing the cache logic is a potential fix, but a better solution may be
to properly handle the suspend resume scenario
in snd_usb_get_cur_mix_value. We may need to mark the cache
in usb_mixer_elem_info to be dirty.

The issue is verified to be reproduced with Dell WH3022 and Logitech USB
Headset H340 by:
1. Boot to OS.
2. Plug in the headset and check sound output.
3. Play an audio/video and keep with low volume.
4. Suspend.
5. Resume.
6. When audio/video is played, the headset's sound output can't keep the
original volume. --> issue "

Would like to know your thoughts on this issue.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A portion of USB Headsets loses previous sound volume setting after a suspend resume
  2021-09-09 10:21 A portion of USB Headsets loses previous sound volume setting after a suspend resume En-Shuo Hsu
@ 2021-09-09 13:30 ` Takashi Iwai
  2021-09-10  9:25   ` Yu-Hsuan Hsu
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2021-09-09 13:30 UTC (permalink / raw)
  To: En-Shuo Hsu; +Cc: alsa-devel, Yu-Hsuan Hsu

On Thu, 09 Sep 2021 12:21:46 +0200,
En-Shuo Hsu wrote:
> 
> Hi 
> 
> We recently found that some USB headsets may fall back to their full volume
> after a suspend and resume. We think the issue is caused by the logic of 
> mixer_ctl_feature_put in sound/usb/mixer.c:
> 
> err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
> if (err < 0)
>   return filter_error(cval, err);
>   val = ucontrol->value.integer.value[cnt];
>   val = get_abs_value(cval, val);
> if (oval != val) {
>   snd_usb_set_cur_mix_value(cval, c + 1, cnt, val);
>   changed = 1;
> }
> 
> The existing codes get the existing mixer control value and ignore the set if
> the val doesn't change. However, in the suspend and resume case, the USB
> headset's control value is actually changed.
> 
> Removing the cache logic is a potential fix, but a better solution may be to
> properly handle the suspend resume scenario in snd_usb_get_cur_mix_value. We
> may need to mark the cache in usb_mixer_elem_info to be dirty.
> 
> The issue is verified to be reproduced with Dell WH3022 and Logitech USB
> Headset H340 by:
> 1. Boot to OS.
> 2. Plug in the headset and check sound output.
> 3. Play an audio/video and keep with low volume.
> 4. Suspend.
> 5. Resume.
> 6. When audio/video is played, the headset's sound output can't keep the
> original volume. --> issue "
> 
> Would like to know your thoughts on this issue.

USB-audio driver has an assumption that the normal resume code
presumes the configuration while reset_resume needs the full
initialization, but this looks too naive, then.

Could you check the following works?


Takashi

--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -1080,7 +1080,7 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
 	 * we just notify and restart the mixers
 	 */
 	list_for_each_entry(mixer, &chip->mixer_list, list) {
-		err = snd_usb_mixer_resume(mixer, reset_resume);
+		err = snd_usb_mixer_resume(mixer, true /*reset_resume*/);
 		if (err < 0)
 			goto err_out;
 	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A portion of USB Headsets loses previous sound volume setting after a suspend resume
  2021-09-09 13:30 ` Takashi Iwai
@ 2021-09-10  9:25   ` Yu-Hsuan Hsu
  2021-09-10 10:18     ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Yu-Hsuan Hsu @ 2021-09-10  9:25 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: ALSA development, En-Shuo Hsu

Takashi Iwai <tiwai@suse.de> 於 2021年9月9日 週四 下午9:30寫道:
>
> On Thu, 09 Sep 2021 12:21:46 +0200,
> En-Shuo Hsu wrote:
> >
> > Hi
> >
> > We recently found that some USB headsets may fall back to their full volume
> > after a suspend and resume. We think the issue is caused by the logic of
> > mixer_ctl_feature_put in sound/usb/mixer.c:
> >
> > err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
> > if (err < 0)
> >   return filter_error(cval, err);
> >   val = ucontrol->value.integer.value[cnt];
> >   val = get_abs_value(cval, val);
> > if (oval != val) {
> >   snd_usb_set_cur_mix_value(cval, c + 1, cnt, val);
> >   changed = 1;
> > }
> >
> > The existing codes get the existing mixer control value and ignore the set if
> > the val doesn't change. However, in the suspend and resume case, the USB
> > headset's control value is actually changed.
> >
> > Removing the cache logic is a potential fix, but a better solution may be to
> > properly handle the suspend resume scenario in snd_usb_get_cur_mix_value. We
> > may need to mark the cache in usb_mixer_elem_info to be dirty.
> >
> > The issue is verified to be reproduced with Dell WH3022 and Logitech USB
> > Headset H340 by:
> > 1. Boot to OS.
> > 2. Plug in the headset and check sound output.
> > 3. Play an audio/video and keep with low volume.
> > 4. Suspend.
> > 5. Resume.
> > 6. When audio/video is played, the headset's sound output can't keep the
> > original volume. --> issue "
> >
> > Would like to know your thoughts on this issue.
>
> USB-audio driver has an assumption that the normal resume code
> presumes the configuration while reset_resume needs the full
> initialization, but this looks too naive, then.
>
> Could you check the following works?
>
>
> Takashi
>
> --- a/sound/usb/card.c
> +++ b/sound/usb/card.c
> @@ -1080,7 +1080,7 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
>          * we just notify and restart the mixers
>          */
>         list_for_each_entry(mixer, &chip->mixer_list, list) {
> -               err = snd_usb_mixer_resume(mixer, reset_resume);
> +               err = snd_usb_mixer_resume(mixer, true /*reset_resume*/);
>                 if (err < 0)
>                         goto err_out;
>         }

Thanks! It works. Is it an appropriate fix to set the reset_resume to
true in usb_audio_resume?
If it's acceptable, we can send the patch.

Yu-Hsuan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A portion of USB Headsets loses previous sound volume setting after a suspend resume
  2021-09-10  9:25   ` Yu-Hsuan Hsu
@ 2021-09-10 10:18     ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-09-10 10:18 UTC (permalink / raw)
  To: Yu-Hsuan Hsu; +Cc: ALSA development, En-Shuo Hsu

On Fri, 10 Sep 2021 11:25:37 +0200,
Yu-Hsuan Hsu wrote:
> 
> Takashi Iwai <tiwai@suse.de> 於 2021年9月9日 週四 下午9:30寫道:
> >
> > On Thu, 09 Sep 2021 12:21:46 +0200,
> > En-Shuo Hsu wrote:
> > >
> > > Hi
> > >
> > > We recently found that some USB headsets may fall back to their full volume
> > > after a suspend and resume. We think the issue is caused by the logic of
> > > mixer_ctl_feature_put in sound/usb/mixer.c:
> > >
> > > err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
> > > if (err < 0)
> > >   return filter_error(cval, err);
> > >   val = ucontrol->value.integer.value[cnt];
> > >   val = get_abs_value(cval, val);
> > > if (oval != val) {
> > >   snd_usb_set_cur_mix_value(cval, c + 1, cnt, val);
> > >   changed = 1;
> > > }
> > >
> > > The existing codes get the existing mixer control value and ignore the set if
> > > the val doesn't change. However, in the suspend and resume case, the USB
> > > headset's control value is actually changed.
> > >
> > > Removing the cache logic is a potential fix, but a better solution may be to
> > > properly handle the suspend resume scenario in snd_usb_get_cur_mix_value. We
> > > may need to mark the cache in usb_mixer_elem_info to be dirty.
> > >
> > > The issue is verified to be reproduced with Dell WH3022 and Logitech USB
> > > Headset H340 by:
> > > 1. Boot to OS.
> > > 2. Plug in the headset and check sound output.
> > > 3. Play an audio/video and keep with low volume.
> > > 4. Suspend.
> > > 5. Resume.
> > > 6. When audio/video is played, the headset's sound output can't keep the
> > > original volume. --> issue "
> > >
> > > Would like to know your thoughts on this issue.
> >
> > USB-audio driver has an assumption that the normal resume code
> > presumes the configuration while reset_resume needs the full
> > initialization, but this looks too naive, then.
> >
> > Could you check the following works?
> >
> >
> > Takashi
> >
> > --- a/sound/usb/card.c
> > +++ b/sound/usb/card.c
> > @@ -1080,7 +1080,7 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
> >          * we just notify and restart the mixers
> >          */
> >         list_for_each_entry(mixer, &chip->mixer_list, list) {
> > -               err = snd_usb_mixer_resume(mixer, reset_resume);
> > +               err = snd_usb_mixer_resume(mixer, true /*reset_resume*/);
> >                 if (err < 0)
> >                         goto err_out;
> >         }
> 
> Thanks! It works. Is it an appropriate fix to set the reset_resume to
> true in usb_audio_resume?
> If it's acceptable, we can send the patch.

Well, if the above works, basically we can get rid of the whole
difference of both resume procedures.  It'd be a good cleanup, too.
I already have a patch, and will submit soon later.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-10 10:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09 10:21 A portion of USB Headsets loses previous sound volume setting after a suspend resume En-Shuo Hsu
2021-09-09 13:30 ` Takashi Iwai
2021-09-10  9:25   ` Yu-Hsuan Hsu
2021-09-10 10:18     ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.