linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Jerome Brunet <jbrunet@baylibre.com>
Subject: [PATCH 5.4 68/92] usb: gadget: f_uac2: reset wMaxPacketSize
Date: Mon, 11 Jan 2021 14:02:12 +0100	[thread overview]
Message-ID: <20210111130042.427175101@linuxfoundation.org> (raw)
In-Reply-To: <20210111130039.165470698@linuxfoundation.org>

From: Jerome Brunet <jbrunet@baylibre.com>

commit 9389044f27081d6ec77730c36d5bf9a1288bcda2 upstream.

With commit 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth")
wMaxPacketSize is computed dynamically but the value is never reset.

Because of this, the actual maximum packet size can only decrease each time
the audio gadget is instantiated.

Reset the endpoint maximum packet size and mark wMaxPacketSize as dynamic
to solve the problem.

Fixes: 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth")
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20201221173531.215169-2-jbrunet@baylibre.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/usb/gadget/function/f_uac2.c |   69 +++++++++++++++++++++++++++--------
 1 file changed, 55 insertions(+), 14 deletions(-)

--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -271,7 +271,7 @@ static struct usb_endpoint_descriptor fs
 
 	.bEndpointAddress = USB_DIR_OUT,
 	.bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
-	.wMaxPacketSize = cpu_to_le16(1023),
+	/* .wMaxPacketSize = DYNAMIC */
 	.bInterval = 1,
 };
 
@@ -280,7 +280,7 @@ static struct usb_endpoint_descriptor hs
 	.bDescriptorType = USB_DT_ENDPOINT,
 
 	.bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
-	.wMaxPacketSize = cpu_to_le16(1024),
+	/* .wMaxPacketSize = DYNAMIC */
 	.bInterval = 4,
 };
 
@@ -348,7 +348,7 @@ static struct usb_endpoint_descriptor fs
 
 	.bEndpointAddress = USB_DIR_IN,
 	.bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
-	.wMaxPacketSize = cpu_to_le16(1023),
+	/* .wMaxPacketSize = DYNAMIC */
 	.bInterval = 1,
 };
 
@@ -357,7 +357,7 @@ static struct usb_endpoint_descriptor hs
 	.bDescriptorType = USB_DT_ENDPOINT,
 
 	.bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
-	.wMaxPacketSize = cpu_to_le16(1024),
+	/* .wMaxPacketSize = DYNAMIC */
 	.bInterval = 4,
 };
 
@@ -444,12 +444,28 @@ struct cntrl_range_lay3 {
 	__le32	dRES;
 } __packed;
 
-static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
+static int set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
 	struct usb_endpoint_descriptor *ep_desc,
-	unsigned int factor, bool is_playback)
+	enum usb_device_speed speed, bool is_playback)
 {
 	int chmask, srate, ssize;
-	u16 max_packet_size;
+	u16 max_size_bw, max_size_ep;
+	unsigned int factor;
+
+	switch (speed) {
+	case USB_SPEED_FULL:
+		max_size_ep = 1023;
+		factor = 1000;
+		break;
+
+	case USB_SPEED_HIGH:
+		max_size_ep = 1024;
+		factor = 8000;
+		break;
+
+	default:
+		return -EINVAL;
+	}
 
 	if (is_playback) {
 		chmask = uac2_opts->p_chmask;
@@ -461,10 +477,12 @@ static void set_ep_max_packet_size(const
 		ssize = uac2_opts->c_ssize;
 	}
 
-	max_packet_size = num_channels(chmask) * ssize *
+	max_size_bw = num_channels(chmask) * ssize *
 		DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1)));
-	ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_packet_size,
-				le16_to_cpu(ep_desc->wMaxPacketSize)));
+	ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_size_bw,
+						    max_size_ep));
+
+	return 0;
 }
 
 /* Use macro to overcome line length limitation */
@@ -670,10 +688,33 @@ afunc_bind(struct usb_configuration *cfg
 	}
 
 	/* Calculate wMaxPacketSize according to audio bandwidth */
-	set_ep_max_packet_size(uac2_opts, &fs_epin_desc, 1000, true);
-	set_ep_max_packet_size(uac2_opts, &fs_epout_desc, 1000, false);
-	set_ep_max_packet_size(uac2_opts, &hs_epin_desc, 8000, true);
-	set_ep_max_packet_size(uac2_opts, &hs_epout_desc, 8000, false);
+	ret = set_ep_max_packet_size(uac2_opts, &fs_epin_desc, USB_SPEED_FULL,
+				     true);
+	if (ret < 0) {
+		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
+		return ret;
+	}
+
+	ret = set_ep_max_packet_size(uac2_opts, &fs_epout_desc, USB_SPEED_FULL,
+				     false);
+	if (ret < 0) {
+		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
+		return ret;
+	}
+
+	ret = set_ep_max_packet_size(uac2_opts, &hs_epin_desc, USB_SPEED_HIGH,
+				     true);
+	if (ret < 0) {
+		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
+		return ret;
+	}
+
+	ret = set_ep_max_packet_size(uac2_opts, &hs_epout_desc, USB_SPEED_HIGH,
+				     false);
+	if (ret < 0) {
+		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
+		return ret;
+	}
 
 	if (EPOUT_EN(uac2_opts)) {
 		agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc);



  parent reply	other threads:[~2021-01-11 13:13 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 13:01 [PATCH 5.4 00/92] 5.4.89-rc1 review Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 01/92] workqueue: Kick a worker based on the actual activation of delayed works Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 02/92] scsi: ufs: Fix wrong print message in dev_err() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 03/92] scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 04/92] scsi: ide: Do not set the RQF_PREEMPT flag for sense requests Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 05/92] scsi: scsi_transport_spi: Set RQF_PM for domain validation commands Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 06/92] lib/genalloc: fix the overflow when size is too big Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 07/92] depmod: handle the case of /sbin/depmod without /sbin in PATH Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 08/92] proc: change ->nlink under proc_subdir_lock Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 09/92] proc: fix lookup in /proc/net subdirectories after setns(2) Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 10/92] i40e: Fix Error I40E_AQ_RC_EINVAL when removing VFs Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 11/92] iavf: fix double-release of rtnl_lock Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 12/92] net: mvpp2: Add TCAM entry to drop flow control pause frames Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 13/92] net: mvpp2: prs: fix PPPoE with ipv6 packet parse Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 14/92] net: systemport: set dev->max_mtu to UMAC_MAX_MTU_SIZE Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 15/92] ethernet: ucc_geth: fix use-after-free in ucc_geth_remove() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 16/92] ethernet: ucc_geth: set dev->max_mtu to 1518 Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 17/92] atm: idt77252: call pci_disable_device() on error path Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 18/92] net: mvpp2: Fix GoP port 3 Networking Complex Control configurations Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 19/92] ibmvnic: continue fatal error reset after passive init Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 20/92] net: ethernet: mvneta: Fix error handling in mvneta_probe Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 21/92] qede: fix offload for IPIP tunnel packets Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 22/92] virtio_net: Fix recursive call to cpus_read_lock() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 23/92] net: dcb: Validate netlink message in DCB handler Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 24/92] net/ncsi: Use real net-device for response handler Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 25/92] net: ethernet: Fix memleak in ethoc_probe Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 26/92] net-sysfs: take the rtnl lock when storing xps_cpus Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 27/92] net-sysfs: take the rtnl lock when accessing xps_cpus_map and num_tc Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 28/92] net-sysfs: take the rtnl lock when storing xps_rxqs Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 29/92] net-sysfs: take the rtnl lock when accessing xps_rxqs_map and num_tc Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 30/92] net: ethernet: ti: cpts: fix ethtool output when no ptp_clock registered Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 31/92] tun: fix return value when the number of iovs exceeds MAX_SKB_FRAGS Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 32/92] net: mvpp2: fix pkt coalescing int-threshold configuration Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 33/92] ipv4: Ignore ECN bits for fib lookups in fib_compute_spec_dst() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 34/92] net: sched: prevent invalid Scell_log shift count Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 35/92] net: hns: fix return value check in __lb_other_process() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 36/92] erspan: fix version 1 check in gre_parse_header() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 37/92] net: hdlc_ppp: Fix issues when mod_timer is called while timer is running Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 38/92] r8169: work around power-saving bug on some chip versions Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 39/92] net: dsa: lantiq_gswip: Enable GSWIP_MII_CFG_EN also for internal PHYs Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 40/92] net: dsa: lantiq_gswip: Fix GSWIP_MII_CFG(p) register access Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 41/92] CDC-NCM: remove "connected" log message Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 42/92] net: usb: qmi_wwan: add Quectel EM160R-GL Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 43/92] vhost_net: fix ubuf refcount incorrectly when sendmsg fails Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 44/92] ionic: account for vlan tag len in rx buffer len Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 45/92] net/sched: sch_taprio: ensure to reset/destroy all child qdiscs Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 46/92] kbuild: dont hardcode depmod path Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 47/92] Bluetooth: revert: hci_h5: close serdev device and free hu in h5_close Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 48/92] video: hyperv_fb: Fix the mmap() regression for v5.4.y and older Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 49/92] crypto: ecdh - avoid buffer overflow in ecdh_set_secret() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 50/92] crypto: asym_tpm: correct zero out potential secrets Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 51/92] powerpc: Handle .text.{hot,unlikely}.* in linker script Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 52/92] staging: mt7621-dma: Fix a resource leak in an error handling path Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 53/92] usb: gadget: enable super speed plus Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 54/92] USB: cdc-acm: blacklist another IR Droid device Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 5.4 55/92] USB: cdc-wdm: Fix use after free in service_outstanding_interrupt() Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 56/92] usb: dwc3: ulpi: Use VStsDone to detect PHY regs access completion Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 57/92] usb: chipidea: ci_hdrc_imx: add missing put_device() call in usbmisc_get_init_data() Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 58/92] USB: xhci: fix U1/U2 handling for hardware with XHCI_INTEL_HOST quirk set Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 59/92] usb: usbip: vhci_hcd: protect shift size Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 60/92] usb: uas: Add PNY USB Portable SSD to unusual_uas Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 61/92] USB: serial: iuu_phoenix: fix DMA from stack Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 62/92] USB: serial: option: add LongSung M5710 module support Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 63/92] USB: serial: option: add Quectel EM160R-GL Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 64/92] USB: yurex: fix control-URB timeout handling Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 65/92] USB: usblp: fix DMA to stack Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 66/92] ALSA: usb-audio: Fix UBSAN warnings for MIDI jacks Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 67/92] usb: gadget: select CONFIG_CRC32 Greg Kroah-Hartman
2021-01-11 13:02 ` Greg Kroah-Hartman [this message]
2021-01-11 13:02 ` [PATCH 5.4 69/92] usb: gadget: function: printer: Fix a memory leak for interface descriptor Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 70/92] usb: gadget: u_ether: Fix MTU size mismatch with RX packet size Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 71/92] USB: gadget: legacy: fix return error code in acm_ms_bind() Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 72/92] usb: gadget: Fix spinlock lockup on usb_function_deactivate Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 73/92] usb: gadget: configfs: Preserve function ordering after bind failure Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 74/92] usb: gadget: configfs: Fix use-after-free issue with udc_name Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 75/92] USB: serial: keyspan_pda: remove unused variable Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 76/92] x86/mm: Fix leak of pmd ptlock Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 77/92] kvm: check tlbs_dirty directly Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 78/92] ALSA: hda/via: Fix runtime PM for Clevo W35xSS Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 79/92] ALSA: hda/conexant: add a new hda codec CX11970 Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 80/92] ALSA: hda/realtek - Fix speaker volume control on Lenovo C940 Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 81/92] ALSA: hda/realtek: Enable mute and micmute LED on HP EliteBook 850 G7 Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 82/92] ALSA: hda/realtek: Add two "Intel Reference board" SSID in the ALC256 Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 83/92] btrfs: send: fix wrong file path when there is an inode with a pending rmdir Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 84/92] Revert "device property: Keep secondary firmware node secondary by type" Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 85/92] dmabuf: fix use-after-free of dmabufs file->f_inode Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 86/92] drm/i915: clear the gpu reloc batch Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 87/92] netfilter: x_tables: Update remaining dereference to RCU Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 88/92] netfilter: ipset: fix shift-out-of-bounds in htable_bits() Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 89/92] netfilter: xt_RATEEST: reject non-null terminated string from userspace Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 90/92] netfilter: nft_dynset: report EOPNOTSUPP on missing set feature Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 91/92] x86/mtrr: Correct the range check before performing MTRR type lookups Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 5.4 92/92] KVM: x86: fix shift out of bounds reported by UBSAN Greg Kroah-Hartman
2021-01-11 21:53 ` [PATCH 5.4 00/92] 5.4.89-rc1 review Guenter Roeck
2021-01-11 23:38 ` Shuah Khan
2021-01-12  6:54 ` Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210111130042.427175101@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=jbrunet@baylibre.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).