From owner-svn-src-head@freebsd.org Tue Dec 25 10:15:49 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5C9F8134CB93; Tue, 25 Dec 2018 10:15:49 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F3B5C6F0D3; Tue, 25 Dec 2018 10:15:48 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C8237AD96; Tue, 25 Dec 2018 10:15:48 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBPAFmGs037059; Tue, 25 Dec 2018 10:15:48 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBPAFmd5037058; Tue, 25 Dec 2018 10:15:48 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201812251015.wBPAFmd5037058@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 25 Dec 2018 10:15:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342456 - head/sys/dev/sound/usb X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/sys/dev/sound/usb X-SVN-Commit-Revision: 342456 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F3B5C6F0D3 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.98)[-0.982,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Dec 2018 10:15:49 -0000 Author: hselasky Date: Tue Dec 25 10:15:48 2018 New Revision: 342456 URL: https://svnweb.freebsd.org/changeset/base/342456 Log: Fix reading of USB sample rate descriptor for SPL Crimson Rev 1. Read first one entry, then try to read the full rate descriptor table. PR: 234380 MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/dev/sound/usb/uaudio.c Modified: head/sys/dev/sound/usb/uaudio.c ============================================================================== --- head/sys/dev/sound/usb/uaudio.c Tue Dec 25 07:39:34 2018 (r342455) +++ head/sys/dev/sound/usb/uaudio.c Tue Dec 25 10:15:48 2018 (r342456) @@ -1520,7 +1520,8 @@ uaudio20_check_rate(struct usb_device *udev, uint8_t i { struct usb_device_request req; usb_error_t error; - uint8_t data[255]; +#define UAUDIO20_MAX_RATES 32 /* we support at maxium 32 rates */ + uint8_t data[2 + UAUDIO20_MAX_RATES * 12]; uint16_t actlen; uint16_t rates; uint16_t x; @@ -1532,19 +1533,57 @@ uaudio20_check_rate(struct usb_device *udev, uint8_t i req.bRequest = UA20_CS_RANGE; USETW2(req.wValue, UA20_CS_SAM_FREQ_CONTROL, 0); USETW2(req.wIndex, clockid, iface_no); - USETW(req.wLength, 255); + /* + * Assume there is at least one rate to begin with, else some + * devices might refuse to return the USB descriptor: + */ + USETW(req.wLength, (2 + 1 * 12)); - error = usbd_do_request_flags(udev, NULL, &req, data, + error = usbd_do_request_flags(udev, NULL, &req, data, USB_SHORT_XFER_OK, &actlen, USB_DEFAULT_TIMEOUT); - if (error != 0 || actlen < 2) - return (USB_ERR_INVAL); + if (error != 0 || actlen < 2) { + /* + * Likely the descriptor doesn't fit into the supplied + * buffer. Try using a larger buffer and see if that + * helps: + */ + rates = MIN(UAUDIO20_MAX_RATES, (255 - 2) / 12); + error = USB_ERR_INVAL; + } else { + rates = UGETW(data); - rates = data[0] | (data[1] << 8); + if (rates > UAUDIO20_MAX_RATES) { + DPRINTF("Too many rates truncating to %d\n", UAUDIO20_MAX_RATES); + rates = UAUDIO20_MAX_RATES; + error = USB_ERR_INVAL; + } else if (rates > 1) { + DPRINTF("Need to read full rate descriptor\n"); + error = USB_ERR_INVAL; + } + } + + if (error != 0) { + /* + * Try to read full rate descriptor. + */ + actlen = (2 + rates * 12); + + USETW(req.wLength, actlen); + + error = usbd_do_request_flags(udev, NULL, &req, data, + USB_SHORT_XFER_OK, &actlen, USB_DEFAULT_TIMEOUT); + + if (error != 0 || actlen < 2) + return (USB_ERR_INVAL); + + rates = UGETW(data); + } + actlen = (actlen - 2) / 12; if (rates > actlen) { - DPRINTF("Too many rates\n"); + DPRINTF("Too many rates truncating to %d\n", actlen); rates = actlen; }