[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190327180158.10245-8-sashal@kernel.org>
Date: Wed, 27 Mar 2019 13:57:43 -0400
From: Sasha Levin <sashal@...nel.org>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
Cc: Mike Rapoport <rppt@...ux.ibm.com>,
Catalin Marinas <catalin.marinas@....com>,
Christophe Leroy <christophe.leroy@....fr>,
Christoph Hellwig <hch@....de>,
"David S. Miller" <davem@...emloft.net>,
Dennis Zhou <dennis@...nel.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Greentime Hu <green.hu@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Guan Xuetao <gxt@....edu.cn>, Guo Ren <guoren@...nel.org>,
Guo Ren <ren_guo@...ky.com>,
Heiko Carstens <heiko.carstens@...ibm.com>,
Juergen Gross <jgross@...e.com>,
Mark Salter <msalter@...hat.com>,
Matt Turner <mattst88@...il.com>,
Max Filippov <jcmvbkbc@...il.com>,
Michael Ellerman <mpe@...erman.id.au>,
Michal Simek <monstr@...str.eu>,
Paul Burton <paul.burton@...s.com>,
Petr Mladek <pmladek@...e.com>,
Richard Weinberger <richard@....at>,
Rich Felker <dalias@...c.org>,
Rob Herring <robh+dt@...nel.org>,
Rob Herring <robh@...nel.org>,
Russell King <linux@...linux.org.uk>,
Stafford Horne <shorne@...il.com>,
Tony Luck <tony.luck@...el.com>,
Vineet Gupta <vgupta@...opsys.com>,
Yoshinori Sato <ysato@...rs.sourceforge.jp>,
Andrew Morton <akpm@...ux-foundation.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Sasha Levin <sashal@...nel.org>,
iommu@...ts.linux-foundation.org
Subject: [PATCH AUTOSEL 5.0 008/262] swiotlb: add checks for the return value of memblock_alloc*()
From: Mike Rapoport <rppt@...ux.ibm.com>
[ Upstream commit a0bf842e89a3842162aa8514b9bf4611c86fee10 ]
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@...ux.ibm.com>
Cc: Catalin Marinas <catalin.marinas@....com>
Cc: Christophe Leroy <christophe.leroy@....fr>
Cc: Christoph Hellwig <hch@....de>
Cc: "David S. Miller" <davem@...emloft.net>
Cc: Dennis Zhou <dennis@...nel.org>
Cc: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Greentime Hu <green.hu@...il.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Guan Xuetao <gxt@....edu.cn>
Cc: Guo Ren <guoren@...nel.org>
Cc: Guo Ren <ren_guo@...ky.com> [c-sky]
Cc: Heiko Carstens <heiko.carstens@...ibm.com>
Cc: Juergen Gross <jgross@...e.com> [Xen]
Cc: Mark Salter <msalter@...hat.com>
Cc: Matt Turner <mattst88@...il.com>
Cc: Max Filippov <jcmvbkbc@...il.com>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Michal Simek <monstr@...str.eu>
Cc: Paul Burton <paul.burton@...s.com>
Cc: Petr Mladek <pmladek@...e.com>
Cc: Richard Weinberger <richard@....at>
Cc: Rich Felker <dalias@...c.org>
Cc: Rob Herring <robh+dt@...nel.org>
Cc: Rob Herring <robh@...nel.org>
Cc: Russell King <linux@...linux.org.uk>
Cc: Stafford Horne <shorne@...il.com>
Cc: Tony Luck <tony.luck@...el.com>
Cc: Vineet Gupta <vgupta@...opsys.com>
Cc: Yoshinori Sato <ysato@...rs.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
kernel/dma/swiotlb.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index c873f9cc2146..41224f0ec40e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -191,6 +191,7 @@ void __init swiotlb_update_mem_attributes(void)
int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
{
unsigned long i, bytes;
+ size_t alloc_size;
bytes = nslabs << IO_TLB_SHIFT;
@@ -203,12 +204,18 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
* to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
* between io_tlb_start and io_tlb_end.
*/
- io_tlb_list = memblock_alloc(
- PAGE_ALIGN(io_tlb_nslabs * sizeof(int)),
- PAGE_SIZE);
- io_tlb_orig_addr = memblock_alloc(
- PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)),
- PAGE_SIZE);
+ alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(int));
+ io_tlb_list = memblock_alloc(alloc_size, PAGE_SIZE);
+ if (!io_tlb_list)
+ panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
+ __func__, alloc_size, PAGE_SIZE);
+
+ alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t));
+ io_tlb_orig_addr = memblock_alloc(alloc_size, PAGE_SIZE);
+ if (!io_tlb_orig_addr)
+ panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
+ __func__, alloc_size, PAGE_SIZE);
+
for (i = 0; i < io_tlb_nslabs; i++) {
io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
--
2.19.1
Powered by blists - more mailing lists