Skip to content

Commit a0bf842

Browse files
rppttorvalds
authored andcommitted
swiotlb: add checks for the return value of memblock_alloc*()
Add panic() calls if memblock_alloc() returns NULL. The panic() format duplicates the one used by memblock itself and in order to avoid explosion with long parameters list replace open coded allocation size calculations with a local variable. Link: http://lkml.kernel.org/r/1548057848-15136-19-git-send-email-rppt@linux.ibm.com Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Christoph Hellwig <hch@lst.de> Cc: "David S. Miller" <davem@davemloft.net> Cc: Dennis Zhou <dennis@kernel.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Greentime Hu <green.hu@gmail.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Guan Xuetao <gxt@pku.edu.cn> Cc: Guo Ren <guoren@kernel.org> Cc: Guo Ren <ren_guo@c-sky.com> [c-sky] Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Juergen Gross <jgross@suse.com> [Xen] Cc: Mark Salter <msalter@redhat.com> Cc: Matt Turner <mattst88@gmail.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Paul Burton <paul.burton@mips.com> Cc: Petr Mladek <pmladek@suse.com> Cc: Richard Weinberger <richard@nod.at> Cc: Rich Felker <dalias@libc.org> Cc: Rob Herring <robh+dt@kernel.org> Cc: Rob Herring <robh@kernel.org> Cc: Russell King <linux@armlinux.org.uk> Cc: Stafford Horne <shorne@gmail.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f5c7310 commit a0bf842

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

kernel/dma/swiotlb.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void __init swiotlb_update_mem_attributes(void)
199199
int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
200200
{
201201
unsigned long i, bytes;
202+
size_t alloc_size;
202203

203204
bytes = nslabs << IO_TLB_SHIFT;
204205

@@ -211,12 +212,18 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
211212
* to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
212213
* between io_tlb_start and io_tlb_end.
213214
*/
214-
io_tlb_list = memblock_alloc(
215-
PAGE_ALIGN(io_tlb_nslabs * sizeof(int)),
216-
PAGE_SIZE);
217-
io_tlb_orig_addr = memblock_alloc(
218-
PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)),
219-
PAGE_SIZE);
215+
alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(int));
216+
io_tlb_list = memblock_alloc(alloc_size, PAGE_SIZE);
217+
if (!io_tlb_list)
218+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
219+
__func__, alloc_size, PAGE_SIZE);
220+
221+
alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t));
222+
io_tlb_orig_addr = memblock_alloc(alloc_size, PAGE_SIZE);
223+
if (!io_tlb_orig_addr)
224+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
225+
__func__, alloc_size, PAGE_SIZE);
226+
220227
for (i = 0; i < io_tlb_nslabs; i++) {
221228
io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
222229
io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;

0 commit comments

Comments
 (0)