Received: by 10.223.185.116 with SMTP id b49csp818636wrg; Sat, 10 Feb 2018 21:05:44 -0800 (PST) X-Google-Smtp-Source: AH8x2279bke0qUXgPHqpYdQ/Rm0IxEimDoC2+CgtapHcoqngpcHXK5qCB6QfnAATM0LMu99Olp3t X-Received: by 10.101.97.5 with SMTP id z5mr6320327pgu.270.1518325544773; Sat, 10 Feb 2018 21:05:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518325544; cv=none; d=google.com; s=arc-20160816; b=IA8cxCzyfA+NEKG6byaO8ZUvQ2k95k95JeifB/8ttVkCc92ehL+tPYaVUz0Wu9UZuA Gp0PBtUluppS7T2T+RTI4t4MigULrqcNlx7N8vxj+UlOg4IDKYFjuGhwlvu4WoG4d6hq x3V6/ttt7o8zBFD7EYJ55nrr00fJZrg//MyC1faJFxJ37DoYRxGoIjjL01DWURc8uf9q 23xFOeitwAiSBRGgXMK54Y0ZnaCyNtn74zYDUxy/NerUmq7hCdBUUSEfiulNFit3Ogp/ ALUCsl3EUlfivYjFRtJhcd8xJ/4NLfS2HgR8KOxOs6oFsEvPU2svbqDyjVzbgoYPmfE3 Agrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=DT6ooxkMTwKbWX/4TkBweaVGV6QdgRh1PjrMNyombc4=; b=rnTqkrGtAdNp2lxieoKZKR61uK5WkA1KU+b56UNohoaxJmGifEI/02vTQ6BBU3aL49 dTKCrK6V1ECXwzSuhbGNSNt/JxaHwRc8EsyOCuJhyQYOkJ+9Fk9VpJj89QPGPf5JPfjM qEx0FJY7gtlFvUfwj2FHG1/wL8K/T5WYWpNHh42lzhP099sl5FQ+D2CN3l2OmTR56ili xja6GNr5ov5Kv0OCZB8iJy2xDgWstwP7jbVfFPDduWfi+EZFJkHVPG+OwBSlud09PV/J REQQGaApPWmSxId6SR3M9nTAi62A+WYb7MOlHW1qYefFOTVlZaE5gx5EzSVN1IvrlGKO 9G+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si2207124pls.65.2018.02.10.21.05.30; Sat, 10 Feb 2018 21:05:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753615AbeBKFD6 (ORCPT + 99 others); Sun, 11 Feb 2018 00:03:58 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41548 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752705AbeBKEdn (ORCPT ); Sat, 10 Feb 2018 23:33:43 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKe-0002hN-PM; Sun, 11 Feb 2018 04:33:40 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKX-0004Tv-Qn; Sun, 11 Feb 2018 04:33:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Alan Stern" , "Greg Kroah-Hartman" , "Minas Harutyunyan" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 31/79] USB: usbfs: compute urb->actual_length for isochronous In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Alan Stern commit 2ef47001b3ee3ded579b7532ebdcf8680e4d8c54 upstream. The USB kerneldoc says that the actual_length field "is read in non-iso completion functions", but the usbfs driver uses it for all URB types in processcompl(). Since not all of the host controller drivers set actual_length for isochronous URBs, programs using usbfs with some host controllers don't work properly. For example, Minas reports that a USB camera controlled by libusb doesn't work properly with a dwc2 controller. It doesn't seem worthwhile to change the HCDs and the documentation, since the in-kernel USB class drivers evidently don't rely on actual_length for isochronous transfers. The easiest solution is for usbfs to calculate the actual_length value for itself, by adding up the lengths of the individual packets in an isochronous transfer. Signed-off-by: Alan Stern CC: Minas Harutyunyan Reported-and-tested-by: wlf Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/usb/core/devio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -1402,6 +1402,18 @@ static int proc_unlinkurb(struct dev_sta return 0; } +static void compute_isochronous_actual_length(struct urb *urb) +{ + unsigned int i; + + if (urb->number_of_packets > 0) { + urb->actual_length = 0; + for (i = 0; i < urb->number_of_packets; i++) + urb->actual_length += + urb->iso_frame_desc[i].actual_length; + } +} + static int processcompl(struct async *as, void __user * __user *arg) { struct urb *urb = as->urb; @@ -1409,6 +1421,7 @@ static int processcompl(struct async *as void __user *addr = as->userurb; unsigned int i; + compute_isochronous_actual_length(urb); if (as->userbuffer && urb->actual_length) { if (urb->number_of_packets > 0) /* Isochronous */ i = urb->transfer_buffer_length; @@ -1581,6 +1594,7 @@ static int processcompl_compat(struct as void __user *addr = as->userurb; unsigned int i; + compute_isochronous_actual_length(urb); if (as->userbuffer && urb->actual_length) { if (urb->number_of_packets > 0) /* Isochronous */ i = urb->transfer_buffer_length;