From patchwork Mon Oct 7 10:06:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfeng Ye X-Patchwork-Id: 11177091 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3F0D76 for ; Mon, 7 Oct 2019 10:06:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C5B5E2084D for ; Mon, 7 Oct 2019 10:06:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Gn79NNaC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5B5E2084D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Date:Message-ID:To:Subject :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=yOISwqoW9cK0IINAgiWZ6k3qLR2LPmQwOfwpCKsDIEg=; b=Gn79NNaCN7Vak0 2ZpP6CbPQBO7yXVg+AKEEsWBjr5pjraMMW+f3ehDCNclf/3mHx49u+fkyrbu6qt1K5m1Rl1g8Mcys jeACShMsU54A+Iwg0ukhAd9osbxHxYP/47+I/r3DdyF13xjxHXywaCLTE3eYGmvYmC/7NP78QOGog e8LMrZFLqaqWoK1qDtT/sqps4lvQvjAWudX5E7hlqvcu7IgbcQr5diVmCimQ1d2MDGh5yrMWdYic9 YxyZL2H6X7bT0YRWpWAB7fud21VCw5yHC2VVxo2foqizrPsUvkgZldGJI5XhEnXVTjEesFAOafHjT GWVeEJnVwCxlDoxH/h6Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iHPug-0006RX-FC; Mon, 07 Oct 2019 10:06:46 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iHPuc-0006QQ-TC for linux-arm-kernel@lists.infradead.org; Mon, 07 Oct 2019 10:06:44 +0000 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C965AD94CD2C7D7E519C; Mon, 7 Oct 2019 18:06:37 +0800 (CST) Received: from [127.0.0.1] (10.177.251.225) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Mon, 7 Oct 2019 18:06:36 +0800 From: Yunfeng Ye Subject: [PATCH v2] arm64: armv8_deprecated: Checking return value for memory allocation To: , , , , , Message-ID: Date: Mon, 7 Oct 2019 18:06:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [10.177.251.225] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191007_030643_112922_2F4308E5 X-CRM114-Status: GOOD ( 13.59 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.32 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org There are no return value checking when using kzalloc() and kcalloc() for memory allocation. so add it. Signed-off-by: Yunfeng Ye --- v1 -> v2: - return error code when memory allocation failure arch/arm64/kernel/armv8_deprecated.c | 57 +++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c index 2ec09de..2284fcb 100644 --- a/arch/arm64/kernel/armv8_deprecated.c +++ b/arch/arm64/kernel/armv8_deprecated.c @@ -168,12 +168,15 @@ static int update_insn_emulation_mode(struct insn_emulation *insn, return ret; } -static void __init register_insn_emulation(struct insn_emulation_ops *ops) +static int __init register_insn_emulation(struct insn_emulation_ops *ops) { unsigned long flags; struct insn_emulation *insn; insn = kzalloc(sizeof(*insn), GFP_KERNEL); + if (!insn) + return -ENOMEM; + insn->ops = ops; insn->min = INSN_UNDEF; @@ -197,6 +200,7 @@ static void __init register_insn_emulation(struct insn_emulation_ops *ops) /* Register any handlers if required */ update_insn_emulation_mode(insn, INSN_UNDEF); + return 0; } static int emulation_proc_handler(struct ctl_table *table, int write, @@ -224,7 +228,7 @@ static int emulation_proc_handler(struct ctl_table *table, int write, return ret; } -static void __init register_insn_emulation_sysctl(void) +static int __init register_insn_emulation_sysctl(void) { unsigned long flags; int i = 0; @@ -233,6 +237,8 @@ static void __init register_insn_emulation_sysctl(void) insns_sysctl = kcalloc(nr_insn_emulated + 1, sizeof(*sysctl), GFP_KERNEL); + if (!insns_sysctl) + return -ENOMEM; raw_spin_lock_irqsave(&insn_emulation_lock, flags); list_for_each_entry(insn, &insn_emulation, node) { @@ -251,6 +257,7 @@ static void __init register_insn_emulation_sysctl(void) raw_spin_unlock_irqrestore(&insn_emulation_lock, flags); register_sysctl("abi", insns_sysctl); + return 0; } /* @@ -617,25 +624,47 @@ static int t16_setend_handler(struct pt_regs *regs, u32 instr) */ static int __init armv8_deprecated_init(void) { - if (IS_ENABLED(CONFIG_SWP_EMULATION)) - register_insn_emulation(&swp_ops); + int ret = 0; + int err = 0; + + if (IS_ENABLED(CONFIG_SWP_EMULATION)) { + ret = register_insn_emulation(&swp_ops); + if (ret) { + pr_err("register insn emulation swp: fail\n"); + err = ret; + } + } - if (IS_ENABLED(CONFIG_CP15_BARRIER_EMULATION)) - register_insn_emulation(&cp15_barrier_ops); + if (IS_ENABLED(CONFIG_CP15_BARRIER_EMULATION)) { + ret = register_insn_emulation(&cp15_barrier_ops); + if (ret) { + pr_err("register insn emulation cpu15_barrier: fail\n"); + err = ret; + } + } if (IS_ENABLED(CONFIG_SETEND_EMULATION)) { - if(system_supports_mixed_endian_el0()) - register_insn_emulation(&setend_ops); - else + if (system_supports_mixed_endian_el0()) { + ret = register_insn_emulation(&setend_ops); + if (ret) { + pr_err("register insn emulation setend: fail\n"); + err = ret; + } + } else { pr_info("setend instruction emulation is not supported on this system\n"); + } } - cpuhp_setup_state_nocalls(CPUHP_AP_ARM64_ISNDEP_STARTING, - "arm64/isndep:starting", - run_all_insn_set_hw_mode, NULL); - register_insn_emulation_sysctl(); + if (nr_insn_emulated) { + cpuhp_setup_state_nocalls(CPUHP_AP_ARM64_ISNDEP_STARTING, + "arm64/isndep:starting", + run_all_insn_set_hw_mode, NULL); + ret = register_insn_emulation_sysctl(); + if (ret) + err = ret; + } - return 0; + return err; } core_initcall(armv8_deprecated_init);