Commit a5e89132 authored by Christoph Hellwig's avatar Christoph Hellwig

swiotlb: use the right nslabs value in swiotlb_init_remap

default_nslabs should only be used to initialize nslabs, after that we
need to use the local variable that can shrink when allocations or the
remap don't succeed.

Fixes: 6424e31b ("swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl")
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarStefano Stabellini <sstabellini@kernel.org>
parent 1521c607
...@@ -234,7 +234,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, ...@@ -234,7 +234,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
{ {
struct io_tlb_mem *mem = &io_tlb_default_mem; struct io_tlb_mem *mem = &io_tlb_default_mem;
unsigned long nslabs = default_nslabs; unsigned long nslabs = default_nslabs;
size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs)); size_t alloc_size;
size_t bytes; size_t bytes;
void *tlb; void *tlb;
...@@ -249,7 +249,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, ...@@ -249,7 +249,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
* memory encryption. * memory encryption.
*/ */
retry: retry:
bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT); bytes = PAGE_ALIGN(nslabs << IO_TLB_SHIFT);
if (flags & SWIOTLB_ANY) if (flags & SWIOTLB_ANY)
tlb = memblock_alloc(bytes, PAGE_SIZE); tlb = memblock_alloc(bytes, PAGE_SIZE);
else else
...@@ -269,12 +269,13 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, ...@@ -269,12 +269,13 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
goto retry; goto retry;
} }
alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
mem->slots = memblock_alloc(alloc_size, PAGE_SIZE); mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
if (!mem->slots) if (!mem->slots)
panic("%s: Failed to allocate %zu bytes align=0x%lx\n", panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
__func__, alloc_size, PAGE_SIZE); __func__, alloc_size, PAGE_SIZE);
swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false); swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
mem->force_bounce = flags & SWIOTLB_FORCE; mem->force_bounce = flags & SWIOTLB_FORCE;
if (flags & SWIOTLB_VERBOSE) if (flags & SWIOTLB_VERBOSE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment