Skip to content

Commit 0c95950

Browse files
Epicuriusgregkh
authored andcommitted
usb: xhci: use array_size() when allocating and freeing memory
Replace size_mul() with array_size() in memory allocation and freeing processes, it fits better semantically. Macro array_size() is identical to size_mult(), which clamps the max size, so it's imperative that array_size() is used when freeing said memory. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://lore.kernel.org/r/20240429140245.3955523-8-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7e2bd7d commit 0c95950

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

drivers/usb/host/xhci-mem.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
536536
struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
537537
{
538538
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
539-
size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
539+
size_t size = array_size(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
540540

541541
if (size > MEDIUM_STREAM_ARRAY_SIZE)
542542
dma_free_coherent(dev, size, stream_ctx, dma);
@@ -561,7 +561,7 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
561561
gfp_t mem_flags)
562562
{
563563
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
564-
size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
564+
size_t size = array_size(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
565565

566566
if (size > MEDIUM_STREAM_ARRAY_SIZE)
567567
return dma_alloc_coherent(dev, size, dma, mem_flags);
@@ -1638,7 +1638,7 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
16381638
goto fail_sp;
16391639

16401640
xhci->scratchpad->sp_array = dma_alloc_coherent(dev,
1641-
size_mul(sizeof(u64), num_sp),
1641+
array_size(sizeof(u64), num_sp),
16421642
&xhci->scratchpad->sp_dma, flags);
16431643
if (!xhci->scratchpad->sp_array)
16441644
goto fail_sp2;
@@ -1671,7 +1671,7 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
16711671
kfree(xhci->scratchpad->sp_buffers);
16721672

16731673
fail_sp3:
1674-
dma_free_coherent(dev, num_sp * sizeof(u64),
1674+
dma_free_coherent(dev, array_size(sizeof(u64), num_sp),
16751675
xhci->scratchpad->sp_array,
16761676
xhci->scratchpad->sp_dma);
16771677

@@ -1700,7 +1700,7 @@ static void scratchpad_free(struct xhci_hcd *xhci)
17001700
xhci->scratchpad->sp_array[i]);
17011701
}
17021702
kfree(xhci->scratchpad->sp_buffers);
1703-
dma_free_coherent(dev, num_sp * sizeof(u64),
1703+
dma_free_coherent(dev, array_size(sizeof(u64), num_sp),
17041704
xhci->scratchpad->sp_array,
17051705
xhci->scratchpad->sp_dma);
17061706
kfree(xhci->scratchpad);
@@ -1778,7 +1778,7 @@ static int xhci_alloc_erst(struct xhci_hcd *xhci,
17781778
struct xhci_segment *seg;
17791779
struct xhci_erst_entry *entry;
17801780

1781-
size = size_mul(sizeof(struct xhci_erst_entry), evt_ring->num_segs);
1781+
size = array_size(sizeof(struct xhci_erst_entry), evt_ring->num_segs);
17821782
erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
17831783
size, &erst->erst_dma_addr, flags);
17841784
if (!erst->entries)
@@ -1829,7 +1829,7 @@ xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
18291829
if (!ir)
18301830
return;
18311831

1832-
erst_size = sizeof(struct xhci_erst_entry) * ir->erst.num_entries;
1832+
erst_size = array_size(sizeof(struct xhci_erst_entry), ir->erst.num_entries);
18331833
if (ir->erst.entries)
18341834
dma_free_coherent(dev, erst_size,
18351835
ir->erst.entries,

0 commit comments

Comments
 (0)