Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp872859ybl; Fri, 10 Jan 2020 08:08:07 -0800 (PST) X-Google-Smtp-Source: APXvYqzOehY9uzY1qIEcRG9cpUBf0CcwPg9KEjyrLp/n63eoO4f4XzaVLZNZtVW1JArFBsZLbQpe X-Received: by 2002:aca:ec93:: with SMTP id k141mr2590720oih.145.1578672487397; Fri, 10 Jan 2020 08:08:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578672487; cv=none; d=google.com; s=arc-20160816; b=LoWgATzYNDLaCBX5QndSx6IKL3itxg6ALbkLcxT85ST4Tdw3tCK0nBYnpBfD5/NsPM SjSojtRDeEz3hEvyKvcsPMgvo9LJSxoQp+4Os9MXdKBTu0d6xcu9vJX9Q6FO7rI0hkIf SmecpW+sw6ub9NChBZTMWkQXc6zImBjXtbZyask97O/RWx1/6C8CpchIEhlkUWBJeWqi aXo/SJQVsTp/e5zH2lE8ga7/cliPPKr1hSx6x3HcpOdgT2xQQZXXs6Q9Hs1fqudFJHSC R3VHt5eVggXZ2XrOhX/lmKBpZz+Ct6MMI+pQBqt9bu8zj7Txl19HDUcoNut8UAku5Ain eEpg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uOG59JZ7AtBijSAMxnt820brgkqhc58hsWEE/GO266c=; b=ruh6TM0JxvsnEI4julPelrRBl0Sbb0xC/OkBtQhipnpawz9X2Ueaoz3Yqhrauu3iJs t4dlYWaMx8afewD7hUjozSQmmcwLLD/pALorMAuCsskJnAgMsp2v1zQ6dBCBjtgJWjsh hT2d+SsbQ46EPNXXxzITKnGAucN8ChnmQSUVwwWnCTHCUM5OCrAC/IEGE17GG2pcL6b7 UxWsj+3H2lFRgZaXaNI6FCoAZfh9Mrbu5mKJx49kRHPI8+EU5v7hQZbTvNAqh5uoGe7X Ik+yLdsPN7kz/EoFvYVNkk2rj+e6R2EIXVqqId+yI78sv9FuP/Mtq7aB5bN9SGruJl54 KJYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h1B+CjfS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26si1614701otj.32.2020.01.10.08.07.51; Fri, 10 Jan 2020 08:08:07 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=h1B+CjfS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728672AbgAJQEj (ORCPT + 99 others); Fri, 10 Jan 2020 11:04:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:52890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728474AbgAJQEi (ORCPT ); Fri, 10 Jan 2020 11:04:38 -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 D433D20838; Fri, 10 Jan 2020 16:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578672277; bh=jxJGane3tS+NEVF1saYYaUXfIpxbAq4LLCBTZkF6BB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h1B+CjfSKdpVXb+obJc3dloDrCBMgOaI4B7CmqkrfIVz/uNRC9+l9obaQbRoEYNKj 53FBZVe6/32Yvp+rxbbkBihttwFXCKPbEgLk1OsXIp2p7I8ahpt6WD6tRhkGRMUnR7 NSLP4T9wF4t7ppJ/gB5u2vqsnrGN71Xux4jsVYdU= From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , Frank Rowand , 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 v6 06/22] init/main.c: Alloc initcall_command_line in do_initcall() and free it Date: Sat, 11 Jan 2020 01:04:31 +0900 Message-Id: <157867227145.17873.17513760552008505454.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157867220019.17873.13377985653744804396.stgit@devnote2> References: <157867220019.17873.13377985653744804396.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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- init/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/init/main.c b/init/main.c index 59c418a57f92..0b4e0c8ccf16 100644 --- a/init/main.c +++ b/init/main.c @@ -137,8 +137,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; @@ -433,10 +431,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); @@ -1044,13 +1038,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); @@ -1063,9 +1056,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); } /*