Skip to content

Commit a5e8913

Browse files
author
Christoph Hellwig
committed
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: 6424e31 ("swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]>
1 parent 1521c60 commit a5e8913

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/dma/swiotlb.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
234234
{
235235
struct io_tlb_mem *mem = &io_tlb_default_mem;
236236
unsigned long nslabs = default_nslabs;
237-
size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
237+
size_t alloc_size;
238238
size_t bytes;
239239
void *tlb;
240240

@@ -249,7 +249,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
249249
* memory encryption.
250250
*/
251251
retry:
252-
bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
252+
bytes = PAGE_ALIGN(nslabs << IO_TLB_SHIFT);
253253
if (flags & SWIOTLB_ANY)
254254
tlb = memblock_alloc(bytes, PAGE_SIZE);
255255
else
@@ -269,12 +269,13 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
269269
goto retry;
270270
}
271271

272+
alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
272273
mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
273274
if (!mem->slots)
274275
panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
275276
__func__, alloc_size, PAGE_SIZE);
276277

277-
swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false);
278+
swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
278279
mem->force_bounce = flags & SWIOTLB_FORCE;
279280

280281
if (flags & SWIOTLB_VERBOSE)

0 commit comments

Comments
 (0)