From patchwork Mon Jan 21 08:04:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 10772953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D5211390 for ; Mon, 21 Jan 2019 08:06:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 409F820415 for ; Mon, 21 Jan 2019 08:06:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3325229DCF; Mon, 21 Jan 2019 08:06:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C609820415 for ; Mon, 21 Jan 2019 08:06:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08ACB8E0026; Mon, 21 Jan 2019 03:06:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 03A5A8E0025; Mon, 21 Jan 2019 03:06:15 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6A658E0026; Mon, 21 Jan 2019 03:06:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id A8C628E0025 for ; Mon, 21 Jan 2019 03:06:14 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id p4so13613373pgj.21 for ; Mon, 21 Jan 2019 00:06:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:message-id; bh=S9DAIifYqejEu33cu4ATs8xjrjQEIJ2H60Bn563dC40=; b=cjCZ+VUXkHfqMdaNj0fjcMtM2pRDhVlFwiQEgUsURDXMrAhOUBHOK8QOQcHvb3PL4P lPScL0zSxJvh9/TzKhVAp+2vVzFaK7mT9Byu0isbEF/gEddQ1ePF7JIxbwLxDQEVlYJm uOJtFQiFm65vptGAF7pDYVUZIz35g8+CSRca4V0cwfBKOReqcH7EBwD1B3VmaI02UCqR 9PNfPEckIf1elxkpKKF2tVoJyZpMBFSCRsb9QuZw6bPrxv5+pPC1FP5nm96GlFFWIf1a fcWnya/UC36Y96pEba3Pc0S27mpcgMz1plEfM4K2OVJd8vG5qItyTHZOax4s77jWoATE YTeA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rppt@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=rppt@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AJcUukcJFrOGNv5KILHQKBtIcoWqyToxP1XfOwxVCJYAe/l523FzdVQx CQBOOxB8RlZeVZndiButz2Vezm1B7XFpy1C2rRdWMUAKM+DqM37t+ePZKd78gEWyVZKfQnGPGDw PZtgcJyvSNyeQVFEPdgYJOJTAXZw6+m9fRbF7LhGI0Kp1UCJxx+9ggYat9pS8ODQTrw== X-Received: by 2002:a62:1e87:: with SMTP id e129mr28702125pfe.221.1548057974316; Mon, 21 Jan 2019 00:06:14 -0800 (PST) X-Google-Smtp-Source: ALg8bN4RLUzzSewGEskCO3LlmI5TyHCeWa2PTQto2affA3iPgrtslIB2IRIx4kBo6LBZysd6jfwb X-Received: by 2002:a62:1e87:: with SMTP id e129mr28702043pfe.221.1548057972940; Mon, 21 Jan 2019 00:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548057972; cv=none; d=google.com; s=arc-20160816; b=H5qmjV5fd1R/gH26HupDmVIq3S9/pFnCJxJO+TqszXrCvmM1IZ9ZA08XnIe1WR7eY4 K5H4jJ6uJVNiohLKXjGO3xipiReQmasPhOPgDag0o60BXPCqBtUcAG8XCW68MQiKUu2q KxpesM1ZG+mKlFpMm7slFbB2DmUbrHNFFLLUHHG6QG1qmaUzCMdopHotO+EpMyTe3Vve nKUbAunzeYbFJZV7cdvZnFYF9xq7Bqt88HwE5BE6m3ZjCFOC++2fnEewgoCFC0It8Olb AG3xIQD0WI9mQ9qcnHYrADVmP5eVmFpWH0tnzQyr7ixcLhY/gfY1x93dGhb1ThBCogPd Tgng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:references:in-reply-to:date:subject:cc:to:from; bh=S9DAIifYqejEu33cu4ATs8xjrjQEIJ2H60Bn563dC40=; b=bLNoY2YR/JuNBr87vCrLdxMB2/bMSrijaICJeeZTKDkbJZKFcBMqnAd4ISlBUGoyT0 wklgTEeVdaCoNCDakbokhQvYPuEMc7yB7GpoPIUHQ5AGvfYMdr76Ozw+cJTCUnqZQScr nlMICfGPbq6qW48R6oDpAbbig5atEHuhMOa0pDt7Wk7GBaBns/laC2+oq9F4Ys2OMe2+ QwgKplGi15zYp1XqUoAHAiMxKHzPKKYKXv8h6gvgDBz5qiugY5rJI5onXtE0C2Z8u9Dn WkqPBvqad8NOUOCT6P/1KG8rtWRlhht7Hb+uuyB5NB5oWUh3yckwD88qAvtWsO2rX33W SuDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rppt@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=rppt@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id n8si11838590plk.9.2019.01.21.00.06.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 00:06:12 -0800 (PST) Received-SPF: pass (google.com: domain of rppt@linux.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rppt@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=rppt@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x0L84MVb080748 for ; Mon, 21 Jan 2019 03:06:12 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2q57sc60av-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 21 Jan 2019 03:06:12 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 21 Jan 2019 08:06:08 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 21 Jan 2019 08:05:56 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0L85t5e37879924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 08:05:55 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98CFC11C05C; Mon, 21 Jan 2019 08:05:55 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1C7B11C050; Mon, 21 Jan 2019 08:05:50 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.207.125]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 21 Jan 2019 08:05:50 +0000 (GMT) Received: by rapoport-lnx (sSMTP sendmail emulation); Mon, 21 Jan 2019 10:05:49 +0200 From: Mike Rapoport To: linux-mm@kvack.org Cc: Andrew Morton , Catalin Marinas , Christoph Hellwig , "David S. Miller" , Dennis Zhou , Geert Uytterhoeven , Greentime Hu , Greg Kroah-Hartman , Guan Xuetao , Guo Ren , Heiko Carstens , Mark Salter , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Paul Burton , Petr Mladek , Rich Felker , Richard Weinberger , Rob Herring , Russell King , Stafford Horne , Tony Luck , Vineet Gupta , Yoshinori Sato , devicetree@vger.kernel.org, kasan-dev@googlegroups.com, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-c6x-dev@linux-c6x.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-um@lists.infradead.org, linux-usb@vger.kernel.org, linux-xtensa@linux-xtensa.org, linuxppc-dev@lists.ozlabs.org, openrisc@lists.librecores.org, sparclinux@vger.kernel.org, uclinux-h8-devel@lists.sourceforge.jp, x86@kernel.org, xen-devel@lists.xenproject.org, Mike Rapoport Subject: [PATCH v2 17/21] init/main: add checks for the return value of memblock_alloc*() Date: Mon, 21 Jan 2019 10:04:04 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548057848-15136-1-git-send-email-rppt@linux.ibm.com> References: <1548057848-15136-1-git-send-email-rppt@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19012108-0028-0000-0000-0000033BE195 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19012108-0029-0000-0000-000023F915AA Message-Id: <1548057848-15136-18-git-send-email-rppt@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-21_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901210066 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 --- init/main.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/init/main.c b/init/main.c index a56f65a..d58a365 100644 --- a/init/main.c +++ b/init/main.c @@ -373,12 +373,20 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { } */ static void __init setup_command_line(char *command_line) { - saved_command_line = - memblock_alloc(strlen(boot_command_line) + 1, SMP_CACHE_BYTES); - initcall_command_line = - memblock_alloc(strlen(boot_command_line) + 1, SMP_CACHE_BYTES); - static_command_line = memblock_alloc(strlen(command_line) + 1, - SMP_CACHE_BYTES); + size_t len = strlen(boot_command_line) + 1; + + saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES); + if (!saved_command_line) + panic("%s: Failed to allocate %zu bytes\n", __func__, len); + + initcall_command_line = memblock_alloc(len, SMP_CACHE_BYTES); + if (!initcall_command_line) + panic("%s: Failed to allocate %zu bytes\n", __func__, len); + + static_command_line = memblock_alloc(len, SMP_CACHE_BYTES); + if (!static_command_line) + panic("%s: Failed to allocate %zu bytes\n", __func__, len); + strcpy(saved_command_line, boot_command_line); strcpy(static_command_line, command_line); } @@ -773,8 +781,14 @@ static int __init initcall_blacklist(char *str) pr_debug("blacklisting initcall %s\n", str_entry); entry = memblock_alloc(sizeof(*entry), SMP_CACHE_BYTES); + if (!entry) + panic("%s: Failed to allocate %zu bytes\n", + __func__, sizeof(*entry)); entry->buf = memblock_alloc(strlen(str_entry) + 1, SMP_CACHE_BYTES); + if (!entry->buf) + panic("%s: Failed to allocate %zu bytes\n", + __func__, strlen(str_entry) + 1); strcpy(entry->buf, str_entry); list_add(&entry->next, &blacklisted_initcalls); }