]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.9-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Nov 2019 00:34:10 +0000 (08:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Nov 2019 00:34:10 +0000 (08:34 +0800)
added patches:
usb-gadget-core-unmap-request-from-dma-only-if-previously-mapped.patch

queue-4.9/series
queue-4.9/usb-gadget-core-unmap-request-from-dma-only-if-previously-mapped.patch [new file with mode: 0644]

index 11221f1ad31397984d3b1b06ca7fee8a531e2a72..b78224adbc92a01e6efce0a0870447ecac9c2794 100644 (file)
@@ -1,3 +1,4 @@
 kvm-mmu-don-t-read-pdptes-when-paging-is-not-enabled.patch
 bluetooth-hci_ldisc-postpone-hci_uart_proto_ready-bit-set-in-hci_uart_set_proto.patch
 mips-bcm63xx-fix-switch-core-reset-on-bcm6368.patch
+usb-gadget-core-unmap-request-from-dma-only-if-previously-mapped.patch
diff --git a/queue-4.9/usb-gadget-core-unmap-request-from-dma-only-if-previously-mapped.patch b/queue-4.9/usb-gadget-core-unmap-request-from-dma-only-if-previously-mapped.patch
new file mode 100644 (file)
index 0000000..79cf17f
--- /dev/null
@@ -0,0 +1,69 @@
+From 31fe084ffaaf8abece14f8ca28e5e3b4e2bf97b6 Mon Sep 17 00:00:00 2001
+From: Jack Pham <jackp@codeaurora.org>
+Date: Tue, 1 Aug 2017 02:00:56 -0700
+Subject: usb: gadget: core: unmap request from DMA only if previously mapped
+
+From: Jack Pham <jackp@codeaurora.org>
+
+commit 31fe084ffaaf8abece14f8ca28e5e3b4e2bf97b6 upstream.
+
+In the SG case this is already handled since a non-zero
+request->num_mapped_sgs is a clear indicator that dma_map_sg()
+had been called. While it would be nice to do the same for the
+singly mapped case by simply checking for non-zero request->dma,
+it's conceivable that 0 is a valid dma_addr_t handle. Hence add
+a flag 'dma_mapped' to struct usb_request and use this to
+determine the need to call dma_unmap_single(). Otherwise, if a
+request is not DMA mapped then the result of calling
+usb_request_unmap_request() would safely be a no-op.
+
+Signed-off-by: Jack Pham <jackp@codeaurora.org>
+Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/usb/gadget/udc/core.c |    5 ++++-
+ include/linux/usb/gadget.h    |    2 ++
+ 2 files changed, 6 insertions(+), 1 deletion(-)
+
+--- a/drivers/usb/gadget/udc/core.c
++++ b/drivers/usb/gadget/udc/core.c
+@@ -817,6 +817,8 @@ int usb_gadget_map_request_by_dev(struct
+                       dev_err(dev, "failed to map buffer\n");
+                       return -EFAULT;
+               }
++
++              req->dma_mapped = 1;
+       }
+       return 0;
+@@ -841,9 +843,10 @@ void usb_gadget_unmap_request_by_dev(str
+                               is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
+               req->num_mapped_sgs = 0;
+-      } else {
++      } else if (req->dma_mapped) {
+               dma_unmap_single(dev, req->dma, req->length,
+                               is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
++              req->dma_mapped = 0;
+       }
+ }
+ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev);
+--- a/include/linux/usb/gadget.h
++++ b/include/linux/usb/gadget.h
+@@ -48,6 +48,7 @@ struct usb_ep;
+  *     by adding a zero length packet as needed;
+  * @short_not_ok: When reading data, makes short packets be
+  *     treated as errors (queue stops advancing till cleanup).
++ * @dma_mapped: Indicates if request has been mapped to DMA (internal)
+  * @complete: Function called when request completes, so this request and
+  *    its buffer may be re-used.  The function will always be called with
+  *    interrupts disabled, and it must not sleep.
+@@ -103,6 +104,7 @@ struct usb_request {
+       unsigned                no_interrupt:1;
+       unsigned                zero:1;
+       unsigned                short_not_ok:1;
++      unsigned                dma_mapped:1;
+       void                    (*complete)(struct usb_ep *ep,
+                                       struct usb_request *req);