From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Rapoport Subject: Re: [PATCH AUTOSEL 5.0 008/262] swiotlb: add checks for the return value of memblock_alloc*() Date: Thu, 28 Mar 2019 07:55:20 +0200 Message-ID: <20190328055520.GA14864@rapoport-lnx> References: <20190327180158.10245-1-sashal@kernel.org> <20190327180158.10245-8-sashal@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20190327180158.10245-8-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org To: Sasha Levin Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Catalin Marinas , Christophe Leroy , Christoph Hellwig , "David S. Miller" , Dennis Zhou , Geert Uytterhoeven , Greentime Hu , Greg Kroah-Hartman , Guan Xuetao , Guo Ren , Guo Ren , Heiko Carstens , Juergen Gross , Mark Salter , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Paul Burton List-Id: iommu@lists.linux-foundation.org Hi, On Wed, Mar 27, 2019 at 01:57:43PM -0400, Sasha Levin wrote: > From: Mike Rapoport > > [ 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. This patch is a part of a series that removes panic() calls from memblock allocators rather than a fix. > Link: http://lkml.kernel.org/r/1548057848-15136-19-git-send-email-rppt@linux.ibm.com > Signed-off-by: Mike Rapoport > Cc: Catalin Marinas > Cc: Christophe Leroy > Cc: Christoph Hellwig > Cc: "David S. Miller" > Cc: Dennis Zhou > Cc: Geert Uytterhoeven > Cc: Greentime Hu > Cc: Greg Kroah-Hartman > Cc: Guan Xuetao > Cc: Guo Ren > Cc: Guo Ren [c-sky] > Cc: Heiko Carstens > Cc: Juergen Gross [Xen] > Cc: Mark Salter > Cc: Matt Turner > Cc: Max Filippov > Cc: Michael Ellerman > Cc: Michal Simek > Cc: Paul Burton > Cc: Petr Mladek > Cc: Richard Weinberger > Cc: Rich Felker > Cc: Rob Herring > Cc: Rob Herring > Cc: Russell King > Cc: Stafford Horne > Cc: Tony Luck > Cc: Vineet Gupta > Cc: Yoshinori Sato > Signed-off-by: Andrew Morton > Signed-off-by: Linus Torvalds > Signed-off-by: Sasha Levin > --- > 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 > -- Sincerely yours, Mike.