Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2282961pxp; Mon, 21 Mar 2022 15:50:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh7BwORq/Oky1oE+tWoZp6ISpKoTt1upJo1fuMETlh1fZh4Ybceo9JXedngZpHv9pjLuNv X-Received: by 2002:a63:af02:0:b0:375:57f0:8af1 with SMTP id w2-20020a63af02000000b0037557f08af1mr19880720pge.188.1647903010698; Mon, 21 Mar 2022 15:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647903010; cv=none; d=google.com; s=arc-20160816; b=at7O6FpTcC5LXGHK4CoGSzlDSS9Yho0pOLG73Tvh9TZKso35bTV0D/79yzDuhl6ag5 VFZoEVCuVOIMH7PWIEMZHt8sYhCyXndw0lX4CGiMntzE5oWB7GOID+qNfBYqoMNrPL33 CsZwL2RPjhIMYoEm3k4APUd0RzwK3orUfvgY8N6pLvs0bUxwpIIvHJGASfS1AKMgvRfx C5Qkiq6NDe1Qi7WQGBggcQ2oXaBen/ipPy+F+kG/NENSOv1M6CF35uhTL9C8yTtFuNUz MDyvcGokS27W1H3t9qKKRid9EE9jvDm+PRwRcgtojd6YxjOQ9Zly6L9odFMCmxoiNJbS lULw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=UFJyO768XA808EkOuTqkbVmBlsA2XWuydVwUrxuy7oY=; b=ZpKuQP1O5HNF7R4CmI8kKKu29JV80CVyd4AP7+XE6v4/mCJ8AAHt0qPQGORVSd67Np iIDN4FBlZMIZhy72Gwz4eRDt4mPJa7PDucYaVS1CPhYxcYKpl76lQnFK6zgsSIErdYC/ krYkApaZHlzcCwHAZk+caMUS9Tql11D/TDsbYlNBYVE1mCrhBmRAyMCWsuSKET6uS8bI H2tU7wdmWDJcE3R+MElVV1I1CY8wJvYMh8/Xp5VIlEgYSEEwLJBUoqMXlBH1rQhL57cD sJ84GZe/MmDy7Hjg9MYhcViFrgoxV6UpCNa+k7amlfhKZl8UucY6unzkzQ58hhb5clmZ UvxA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s3-20020a656903000000b003822d0bffa5si11325780pgq.27.2022.03.21.15.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:50:10 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6C8764723; Mon, 21 Mar 2022 14:58:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237789AbiCRPG6 (ORCPT + 99 others); Fri, 18 Mar 2022 11:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237758AbiCRPGx (ORCPT ); Fri, 18 Mar 2022 11:06:53 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F0FF41330; Fri, 18 Mar 2022 08:05:33 -0700 (PDT) Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxqsywnzRicaQLAA--.9144S4; Fri, 18 Mar 2022 23:05:21 +0800 (CST) From: Tiezhu Yang To: Thomas Bogendoerfer Cc: Xuefeng Li , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] MIPS: Return -EINVAL if mem parameter is invalid in early_parse_mem() Date: Fri, 18 Mar 2022 23:05:19 +0800 Message-Id: <1647615920-23103-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1647615920-23103-1-git-send-email-yangtiezhu@loongson.cn> References: <1647615920-23103-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9AxqsywnzRicaQLAA--.9144S4 X-Coremail-Antispam: 1UD129KBjvJXoW7CrWrXryfZrW5AF48Gr1ftFb_yoW8CF18pr 40y343tr4UWr97Za4Syr95W34fJ3Z5trW3XayxGr1rJ3WUXr1UJw48XFyayryjgrW8ta4j 9rsYva4UGwsrCFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBI14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1l84 ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I2 62IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcV AFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG 0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6ryrMxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aV CY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUUzpBDUUUUU== X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 In the current code, the users usually need to make sure the value of mem parameter is correct, but it is better to do some check to avoid potential boot hangs. This commit checks whether the first mem parameter is invalid, if yes, return -EINVAL before call memblock_remove() and memblock_add(). Signed-off-by: Tiezhu Yang --- arch/mips/kernel/setup.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 14aa8bd..c8c8f60 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -343,12 +343,19 @@ static int usermem __initdata; static int __init early_parse_mem(char *p) { phys_addr_t start, size; + phys_addr_t pa_start, pa_end; + u64 idx; if (!p) { pr_err("mem parameter is empty, do nothing\n"); return -EINVAL; } + start = 0; + size = memparse(p, &p); + if (*p == '@') + start = memparse(p + 1, &p); + /* * If a user specifies memory size, we * blow away any automatically generated @@ -356,13 +363,20 @@ static int __init early_parse_mem(char *p) */ if (usermem == 0) { usermem = 1; + for_each_mem_range(idx, &pa_start, &pa_end) { + if (start >= pa_start && size <= pa_end - pa_start) + break; + + if (idx < memblock.memory.cnt) + continue; + + usermem = -1; + pr_err("mem parameter is invalid, do nothing\n"); + return -EINVAL; + } memblock_remove(memblock_start_of_DRAM(), memblock_end_of_DRAM() - memblock_start_of_DRAM()); } - start = 0; - size = memparse(p, &p); - if (*p == '@') - start = memparse(p + 1, &p); memblock_add(start, size); @@ -638,7 +652,7 @@ static void __init arch_mem_init(char **cmdline_p) parse_early_param(); - if (usermem) + if (usermem == 1) pr_info("User-defined physical RAM map overwrite\n"); check_kernel_sections_mem(); -- 2.1.0