[PATCH 18/21] swiotlb: add checks for the return value of memblock_alloc*()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: linux-mm@xxxxxxxxx
- Subject: [PATCH 18/21] swiotlb: add checks for the return value of memblock_alloc*()
- From: Mike Rapoport <rppt@xxxxxxxxxxxxx>
- Date: Wed, 16 Jan 2019 15:44:18 +0200
- Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, Christoph Hellwig <hch@xxxxxx>, "David S. Miller" <davem@xxxxxxxxxxxxx>, Dennis Zhou <dennis@xxxxxxxxxx>, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Greentime Hu <green.hu@xxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Guan Xuetao <gxt@xxxxxxxxxx>, Guo Ren <guoren@xxxxxxxxxx>, Heiko Carstens <heiko.carstens@xxxxxxxxxx>, Mark Salter <msalter@xxxxxxxxxx>, Matt Turner <mattst88@xxxxxxxxx>, Max Filippov <jcmvbkbc@xxxxxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, Michal Simek <monstr@xxxxxxxxx>, Paul Burton <paul.burton@xxxxxxxx>, Petr Mladek <pmladek@xxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, Richard Weinberger <richard@xxxxxx>, Rob Herring <robh+dt@xxxxxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxx>, Stafford Horne <shorne@xxxxxxxxx>, Tony Luck <tony.luck@xxxxxxxxx>, Vineet Gupta <vgupta@xxxxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxxxxxxxxx>, devicetree@xxxxxxxxxxxxxxx, kasan-dev@xxxxxxxxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-c6x-dev@xxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, linux-m68k@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, linux-sh@xxxxxxxxxxxxxxx, linux-snps-arc@xxxxxxxxxxxxxxxxxxx, linux-um@xxxxxxxxxxxxxxxxxxx, linux-usb@xxxxxxxxxxxxxxx, linux-xtensa@xxxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, openrisc@xxxxxxxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, uclinux-h8-devel@xxxxxxxxxxxxxxxxxxxx, x86@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, Mike Rapoport <rppt@xxxxxxxxxxxxx>
- In-reply-to: <1547646261-32535-1-git-send-email-rppt@linux.ibm.com>
- References: <1547646261-32535-1-git-send-email-rppt@linux.ibm.com>
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.
Signed-off-by: Mike Rapoport <rppt@xxxxxxxxxxxxx>
---
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 d636177..e78835c8 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.7.4
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]