Before this a device needing ie 32 stream ctxs would end up with an entry from
the small_streams_pool which has 256 bytes entries, where as 32 stream ctxs
need 512 bytes. Things actually keep running for a surprisingly long time
before crashing because of this.

Signed-off-by: Hans de Goede <hdego...@redhat.com>
Signed-off-by: Sarah Sharp <sarah.a.sh...@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 1d39b35..a455c56 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -519,12 +519,12 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
                struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
 {
        struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
+       size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
-       if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE)
-               dma_free_coherent(&pdev->dev,
-                               sizeof(struct xhci_stream_ctx)*num_stream_ctxs,
+       if (size > MEDIUM_STREAM_ARRAY_SIZE)
+               dma_free_coherent(&pdev->dev, size,
                                stream_ctx, dma);
-       else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE)
+       else if (size <= SMALL_STREAM_ARRAY_SIZE)
                return dma_pool_free(xhci->small_streams_pool,
                                stream_ctx, dma);
        else
@@ -547,12 +547,12 @@ static struct xhci_stream_ctx 
*xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
                gfp_t mem_flags)
 {
        struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
+       size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
-       if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE)
-               return dma_alloc_coherent(&pdev->dev,
-                               sizeof(struct xhci_stream_ctx)*num_stream_ctxs,
+       if (size > MEDIUM_STREAM_ARRAY_SIZE)
+               return dma_alloc_coherent(&pdev->dev, size,
                                dma, mem_flags);
-       else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE)
+       else if (size <= SMALL_STREAM_ARRAY_SIZE)
                return dma_pool_alloc(xhci->small_streams_pool,
                                mem_flags, dma);
        else
-- 
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to