Coping with short replies in usbmixer
PATCH 1/1 Coping with short replies in usbmixer
Hi,
while trying to find out why a USB handset (Yealink P1K) frequently gets muted when changing volume, I found that short USB responses cause the problem.
The function get_ctl_value(..) in usbmixer.c requests the state of a certain control and retries up to 10 times if an error occurs. However a short USB response is not treated as an error as neither the transfer flag URB_SHORT_NOT_OK is set nor is the return value of snd_usb_ctl_msg(..) compared with the requested amount of data. As a result the function get_ctl_value(..) might not retry the USB request but returns an unpredictable result without reporting an error.
The attached patch forces the number of returned bytes to be at least val_len. It was generated from kernel version 2.6.21. If there are any issues with the patch please let me know. Otherwise I would be happy if it could be applied to the ALSA sources. Regards,
-Thomas
sound/usb/usbmixer.c +1 -1
@@ -360,7 +360,7 @@ static int get_ctl_value(struct usb_mixe request, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, validx, cval->mixer->ctrlif | (cval->id << 8), - buf, val_len, 100) >= 0) { + buf, val_len, 100) >= val_len) { *value_ret =convert_signed_value (cval,snd_usb_combine_bytes (buf, val_len));return 0 ; }
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
At Fri, 11 May 2007 22:28:16 +0200,
Quoted 14 lines · [email protected] wrote:
Hi,
while trying to find out why a USB handset (Yealink P1K) frequently gets muted when changing volume, I found that short USB responses cause the problem.The function
get_ctl_value(..)inusbmixer.crequests the state of a certain control and retries up to 10 times if an error occurs. However a short USB response is not treated as an error as neither the transfer flagURB_SHORT_NOT_OKis set nor is the return value ofsnd_usb_ctl_msg(..)compared with the requested amount of data. As a result the functionget_ctl_value(..)might not retry the USB request but returns an unpredictable result without reporting an error.
Quoted 6 lines
The attached patch forces the number of returned bytes to be at least
val_len. It was generated from kernel version 2.6.21. If there are any issues with the patch please let me know. Otherwise I would be happy if it could be applied to the ALSA sources.
Regards,
-Thomas
Thanks, the patch looks good.
Could you give a sign-off to merge to the upstream?
Takashi
Quoted 18 lines
[2 usbmixer.patch <text/x-patch (7bit)>]
diff -rupa/sound/usb/usbmixer.cb/sound/usb/usbmixer.csound/usb/usbmixer.c +1
-1@@ -360,7 +360,7 @@ static int get_ctl_value(struct usb_mixe request, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, validx, cval->mixer->ctrlif | (cval->id << 8), - buf, val_len, 100) >= 0) { + buf, val_len, 100) >= val_len) { *value_ret =convert_signed_value (cval,snd_usb_combine_bytes (buf, val_len));return 0 ; }[3 <text/plain; us-ascii (7bit)>]
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel