From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AB60C2D0DA for ; Thu, 26 Dec 2019 14:05:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B5AE20828 for ; Thu, 26 Dec 2019 14:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577369108; bh=QY76Hs0hSUfQ8Vu84T8I8Y51eyKVQZohwC0KG6uxJVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dOZu77ZpU5on7qYLxDI259sWR77Bm2BoEcd9OrQ2U8poGVJYGSLDMTU/xumedT5mn fty1+m6b/dVrDDVxJxsE4xDSrPO8kqHeqIRfWv9vHFQ55AVAWYv0DBDXuk62PQhA7c YdBJBLzhxdkwiPDMKgKlWV0V7KoXaXPeew+SmEcQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726450AbfLZOFI (ORCPT ); Thu, 26 Dec 2019 09:05:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:51268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbfLZOFH (ORCPT ); Thu, 26 Dec 2019 09:05:07 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE7AC20CC7; Thu, 26 Dec 2019 14:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577369107; bh=QY76Hs0hSUfQ8Vu84T8I8Y51eyKVQZohwC0KG6uxJVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZTqkr3ME6bBP3BuvuHjA8bOyG7Lap0+oQFe1eJmF636lMTf5yIjkIByqfJNHELDEr 3Recsv/8DNdPLdvVJCneAPYmMobpxExaUEoS1IV9et5+/Rb0WDegDFDsUXdBQEjB5E 8Fo2BaIYh7Dgl1akmHUa1U5AWqKvU03fNZSVRgXc= From: Masami Hiramatsu To: Steven Rostedt , Frank Rowand Cc: Ingo Molnar , Randy Dunlap , Namhyung Kim , Tim Bird , Jiri Olsa , Arnaldo Carvalho de Melo , Tom Zanussi , Rob Herring , Andrew Morton , Thomas Gleixner , Greg Kroah-Hartman , Alexey Dobriyan , Jonathan Corbet , Linus Torvalds , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 06/22] init/main.c: Alloc initcall_command_line in do_initcall() and free it Date: Thu, 26 Dec 2019 23:05:00 +0900 Message-Id: <157736910004.11126.8700418489018796985.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157736902773.11126.2531161235817081873.stgit@devnote2> References: <157736902773.11126.2531161235817081873.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org Since initcall_command_line is used as a temporary buffer, it could be freed after usage. Allocate it in do_initcall() and free it after used. Signed-off-by: Masami Hiramatsu --- 0 files changed diff --git a/init/main.c b/init/main.c index a47a95076405..29830cb1b198 100644 --- a/init/main.c +++ b/init/main.c @@ -138,8 +138,6 @@ char __initdata boot_command_line[COMMAND_LINE_SIZE]; char *saved_command_line; /* Command line for parameter parsing */ static char *static_command_line; -/* Command line for per-initcall parameter parsing */ -static char *initcall_command_line; static char *execute_command; static char *ramdisk_execute_command; @@ -434,10 +432,6 @@ static void __init setup_command_line(char *command_line) 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); @@ -1045,13 +1039,12 @@ static const char *initcall_level_names[] __initdata = { "late", }; -static void __init do_initcall_level(int level) +static void __init do_initcall_level(int level, char *command_line) { initcall_entry_t *fn; - strcpy(initcall_command_line, saved_command_line); parse_args(initcall_level_names[level], - initcall_command_line, __start___param, + command_line, __start___param, __stop___param - __start___param, level, level, NULL, &repair_env_string); @@ -1064,9 +1057,20 @@ static void __init do_initcall_level(int level) static void __init do_initcalls(void) { int level; + size_t len = strlen(saved_command_line) + 1; + char *command_line; + + command_line = kzalloc(len, GFP_KERNEL); + if (!command_line) + panic("%s: Failed to allocate %zu bytes\n", __func__, len); + + for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) { + /* Parser modifies command_line, restore it each time */ + strcpy(command_line, saved_command_line); + do_initcall_level(level, command_line); + } - for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) - do_initcall_level(level); + kfree(command_line); } /*