From patchwork Thu Nov 3 01:18:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liao Chang X-Patchwork-Id: 14581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp250637wru; Wed, 2 Nov 2022 18:27:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7YHXgg8d/bTk8ajrlGI0VUGu3tCY2KyyLtZKPcDrL/LGW39xFyL4dZ4VOKcT0PFcsVHuD/ X-Received: by 2002:a17:907:2d1e:b0:7a9:c2f9:2c2c with SMTP id gs30-20020a1709072d1e00b007a9c2f92c2cmr26295936ejc.405.1667438831456; Wed, 02 Nov 2022 18:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667438831; cv=none; d=google.com; s=arc-20160816; b=R51rZZJKnz7SKbCjj/u4g51d75ntUmNIgdyigGKGI5GYl7DW5GUJXK2CqE2gZF+Qwd vwfNE3szCMMZBDaVTqqm9xE8j4wJBjwcIPOpbAKF2wXIJ761y2grJcR17O4c+6HzAkUv hgG33K2ciuGGPyjbtyKKzykcWtPXweIiFhgNBv3uuiaY3TzZYf5nVZ/gDoj9v2D7N5vj +p0ubL5xBPkDEUabwjhFC4FLnsY7GibaRVcywUhYPkYV92uPS/9hxZr+0vk+3uMkg+J2 FoZtMaPfK7FTm3JFYPpCljFMqsAf0lNHy2cY7i0cSHwfBQol1Ld0Wz1fUPQEHxQHrhvL NaHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=Ro4C0qyLv+MVo9l7dv2NJ/4PR0pafI3IAGsoNh62yXw=; b=PywPMRESP7UaKNXYXP45td8lvCNyrR/Pr/hxoeh+CUBhv7NHQ4YILX6/xgr9k9ocV1 B9Ro0U4ecDKR1IIhstMgWwXoxEEmBAb7d6seSpwr6oijJEtqKqvSKOd2JF9zz1y/1cQQ 7skBlTE03a6jCR8zAblB3SxLsTHioCzVZ4rPgWbQflVSJNsmxe8e+j00ydWJe2I83CVm kqix8hkwQv3nCa2EY4p+oUf8CMg2raNotWRaq0K0+159fni07X5bzBq6PZJfjTCMd8RH tijpwKL7rU6IrZAICwyyHjH5mn2JbZ0B7nC1PVYYZhJyJdgg5DiizNs6V/rn9stROQvz 9Pjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020aa7c0c8000000b0043d54ba0a4dsi14205204edp.327.2022.11.02.18.26.47; Wed, 02 Nov 2022 18:27:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbiKCBVe (ORCPT + 99 others); Wed, 2 Nov 2022 21:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbiKCBVd (ORCPT ); Wed, 2 Nov 2022 21:21:33 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81BAF12745; Wed, 2 Nov 2022 18:21:32 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N2m9S0GdMzJnQ1; Thu, 3 Nov 2022 09:18:36 +0800 (CST) Received: from huawei.com (10.67.174.53) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 3 Nov 2022 09:21:30 +0800 From: Liao Chang To: , , , , CC: , , Subject: [PATCH] MIPS: Loongson64: Add WARN_ON on kexec related kmalloc failed Date: Thu, 3 Nov 2022 09:18:15 +0800 Message-ID: <20221103011815.139424-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748436340198940174?= X-GMAIL-MSGID: =?utf-8?q?1748436340198940174?= Add WARN_ON on kexec related kmalloc failed, avoid to pass NULL pointer to following memcpy and loongson_kexec_prepare. Fixes: 6ce48897ce47 ("MIPS: Loongson64: Add kexec/kdump support") Signed-off-by: Liao Chang --- arch/mips/loongson64/reset.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/mips/loongson64/reset.c b/arch/mips/loongson64/reset.c index 758d5d26aaaa..e420800043b0 100644 --- a/arch/mips/loongson64/reset.c +++ b/arch/mips/loongson64/reset.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -159,8 +160,17 @@ static int __init mips_reboot_setup(void) #ifdef CONFIG_KEXEC kexec_argv = kmalloc(KEXEC_ARGV_SIZE, GFP_KERNEL); + if (WARN_ON(!kexec_argv)) + return -ENOMEM; + kdump_argv = kmalloc(KEXEC_ARGV_SIZE, GFP_KERNEL); + if (WARN_ON(!kdump_argv)) + return -ENOMEM; + kexec_envp = kmalloc(KEXEC_ENVP_SIZE, GFP_KERNEL); + if (WARN_ON(!kexec_envp)) + return -ENOMEM; + fw_arg1 = KEXEC_ARGV_ADDR; memcpy(kexec_envp, (void *)fw_arg2, KEXEC_ENVP_SIZE);