Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5657158img; Wed, 27 Mar 2019 12:35:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKswfi3ChkrpTxgJA0Y0HoI+yugM6Z0wghZZn7hdXEPiY77/g42lK9yZjPmWCeZ82lnHWM X-Received: by 2002:a17:902:f24:: with SMTP id 33mr36971474ply.47.1553715304926; Wed, 27 Mar 2019 12:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715304; cv=none; d=google.com; s=arc-20160816; b=hu80X7Ppd957zM5dFq7DftW6nf+2mW0RzCXFwp/eo0LmIF1BQhxHToBpIK1mlKl20e 6BPqTR0Buz1XnPOtoE4R1ujPqpFDadtM5UygGYYZ3PIyCYtyoLfyArFuo2hG6grwwIct BLqKqyDhgFur5iCwk+9RXeqVREdjSbgwYU4VAJKTyTw/R6jg1H9VplP4pCXOVi0usB+8 kAIsoe4Av8K2c1LyT9GUcA/3QZIiyODuBX2crxmT9gg4m2lG8vrjix1momkQdq03lKiT Ckbr+7b6+WtUNJQmeu9jSoH3mn39cFPF/B0E+BKxLnSAFIZZdzS299JzpRy8XUmjAZyT sonw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z25ClvcI18Bp5bHbKpTMOGO3DYiML6HyGH77PiiVHqE=; b=jfIgyOoXRvx3hkv2HlMymNNh39d4QALxuipqNOw1BYP3n9j2nP1ohuu927kEhbQvzl GSdK8CT7wPpboyEjKLv9PPolA54IqOSBiWRTg1IH9roTYz5FKtKy+04ILxSQNzmU/Jkr znHXTBD5LtPA0LUw9kTIKYUqU9StJl3PNXJK0AHN0Y1fIhRmaAXKJ+yN6BlKnbEYevrT +26xa2EQsx9nonskYjXwi2vxuunBrlkxBizUsRLCFa1WcKYXBRUaIkvdEVVSNYrWj0VO yRFC2kayQiVfIo0LHYh6f0Wf6xvx0BdBbpkJY9qZSR7107yvFWqvM43omJ46hpbmHnFA ax3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i3PBpV2F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p66si20176669pfp.231.2019.03.27.12.34.49; Wed, 27 Mar 2019 12:35:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i3PBpV2F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731178AbfC0TeR (ORCPT + 99 others); Wed, 27 Mar 2019 15:34:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729234AbfC0SCL (ORCPT ); Wed, 27 Mar 2019 14:02:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0F94C2173C; Wed, 27 Mar 2019 18:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709730; bh=vocEwnbZp/TrmugDuJcC5kb7NwJKwfyOUE3Qe/SKxwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i3PBpV2FdYVUxmYSSvV4LfpwZtqS3Xp10w85i0XaNd0pGoJAXPL5lj1+/c7o+xBqh 9IfOkMN72Gd/ANdm4KZJMTGFnZLlfz8PhclXiiYEthvIpEF/WWMo0BlFu07K01IHyc yBwMp5m/vur9yJZM58/9K3msqF45+PX86Xm0/FLg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mike Rapoport , 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 , Petr Mladek , Richard Weinberger , Rich Felker , Rob Herring , Rob Herring , Russell King , Stafford Horne , Tony Luck , Vineet Gupta , Yoshinori Sato , Andrew Morton , Linus Torvalds , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 5.0 008/262] swiotlb: add checks for the return value of memblock_alloc*() Date: Wed, 27 Mar 2019 13:57:43 -0400 Message-Id: <20190327180158.10245-8-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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