Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4095706ybp; Mon, 7 Oct 2019 03:09:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8TotuC+VZVg7iRnyV2U2n6zdH9zZS+W8KYRRqOzj5d11pHHr4+XFAu1sZ21Mh8qOo21Nw X-Received: by 2002:a50:dac2:: with SMTP id s2mr28207479edj.26.1570442950925; Mon, 07 Oct 2019 03:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570442950; cv=none; d=google.com; s=arc-20160816; b=p748/CNiRtZ+JPFrEdsVCinJ49VMJrzo7OyyxJpbeAwHmbJj5tU5r1fzRqujBNCp9k K87o1tD9zQRFwIKABXd3a83u6QmqUSiQLBSLDue7WC8Yi8cEWvx8hrbIvzxJ8bmcBFqi 4TnKqZYOHdy+pEs4xbsiYKC+S4Jy8Z3EcMl2dYE4y/OiwcmNodyL9wCUmu4//gV+8K59 mPQFjwzre30MbvldJXaLnsOdZgAg6XfFSvcLnW+Vet1cBAbVaBpgImWaxFLYVDWsx37E YMQTC+tO4dpv/H71CNCImfMFFal9yP+wcwMbao49IxuW1hSrBQGgmKi1PZCSA9yR372i rM9A== 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 :content-language:mime-version:user-agent:date:message-id:cc:to :subject:from; bh=RhPAaWnFup8CLiS3oQNo+U2zOm2iMASopoLgID2SMGE=; b=xfD4IF+mZLeRUS6yA3PjugAMnyVOkbYztLESCY0b1xzHyu7KW6gTUyf2nY5XGBDy6I 9R+gOu6jDj8WLlzzchOWaHAmQqjVv4DTmwGOZi7TXYIcohiKtbAZX93sY374QuklhKdZ oE0sSwMOvcx/FoUyEF+p+0hqF5nOZluy1m72ifsyAwLcF6dlU6fuODo4NJ426VFDI3Ri ptkycWVkJPE+zgEKdBn85jNwb5mVmQ5cMebLa2fCfd0K40AhgMcrj5dqlpuiTEIgTITL OZibwEavelep3wAesdb5O/riMD8zSE9Vf1uSc66hC6SoNVQ1YD6M2rkd1GukWNOnmekm 7MwA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si5480081eju.406.2019.10.07.03.08.47; Mon, 07 Oct 2019 03:09:10 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727524AbfJGKGl (ORCPT + 99 others); Mon, 7 Oct 2019 06:06:41 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:46844 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727262AbfJGKGk (ORCPT ); Mon, 7 Oct 2019 06:06:40 -0400 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: , , , , , CC: , 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-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.251.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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); -- 1.8.3.1