From patchwork Thu Sep 16 06:23:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12498125 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, 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 C6A96C433EF for ; Thu, 16 Sep 2021 06:23:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 60D6A61207 for ; Thu, 16 Sep 2021 06:23:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 60D6A61207 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0981F940008; Thu, 16 Sep 2021 02:23:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0486A6B0072; Thu, 16 Sep 2021 02:23:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7A53940008; Thu, 16 Sep 2021 02:23:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id DA0806B0071 for ; Thu, 16 Sep 2021 02:23:15 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 950992D4A9 for ; Thu, 16 Sep 2021 06:23:15 +0000 (UTC) X-FDA: 78592444350.28.A04C94C Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf04.hostedemail.com (Postfix) with ESMTP id 563D250000B3 for ; Thu, 16 Sep 2021 06:23:15 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 5279E611CA; Thu, 16 Sep 2021 06:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631773394; bh=tjYE+w+hVKFuNE7M94ifyu2S6XUIpnaX8UMLFXe0coU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MwxvbaDFsFzJ0WbuMDAhQxGz/QZ32erbRaFMpTAonzvMiZydGTsKs5oL/JGb9gB++ 2efsqfpYklFXhsEVzQICxeLwaa4R3VpphL14ekzIMTZKs/ezdJpXfKXfLlcseRl8iT JmAz4N8KNBdOVH4rKiOxW/uBGcJSftOWd8VxjMw9AoLegyAXJIdnjId1BNSWX9o4M4 /AbiAetqvRmUo+R8Jp8hOjqk/OT6h1HXiWyz3yLXEa7hFPdF70Q/DxAUAnLptJe8r+ f8ZuVJIkt7JqYBUju9hvSti6nQgzROJ1saFL8n+Pi+WnWOaf1lmNMi/zan62sqvRXd JV1cA2GLd6biQ== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v4 1/4] bootconfig: init: Fix memblock leak in xbc_make_cmdline() Date: Thu, 16 Sep 2021 15:23:12 +0900 Message-Id: <163177339181.682366.8713781325929549256.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163177338366.682366.5998343833719057348.stgit@devnote2> References: <163177338366.682366.5998343833719057348.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 563D250000B3 X-Stat-Signature: b6mry9m4sr64738scd51rsoknr49hums Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MwxvbaDF; spf=pass (imf04.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1631773395-674794 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Free unused memblock in a error case to fix memblock leak in xbc_make_cmdline(). Fixes: 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig for kernel command line") Signed-off-by: Masami Hiramatsu --- init/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/init/main.c b/init/main.c index 3f7216934441..0b054fff8e92 100644 --- a/init/main.c +++ b/init/main.c @@ -382,6 +382,7 @@ static char * __init xbc_make_cmdline(const char *key) ret = xbc_snprint_cmdline(new_cmdline, len + 1, root); if (ret < 0 || ret > len) { pr_err("Failed to print extra kernel cmdline.\n"); + memblock_free_ptr(new_cmdline, len + 1); return NULL; } From patchwork Thu Sep 16 06:23:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12498127 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, 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 B9064C433F5 for ; Thu, 16 Sep 2021 06:23:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4E28060E76 for ; Thu, 16 Sep 2021 06:23:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4E28060E76 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E7AA9940009; Thu, 16 Sep 2021 02:23:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E2AC76B0072; Thu, 16 Sep 2021 02:23:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1A82940009; Thu, 16 Sep 2021 02:23:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id C51F96B0071 for ; Thu, 16 Sep 2021 02:23:24 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 69BEF82499A8 for ; Thu, 16 Sep 2021 06:23:24 +0000 (UTC) X-FDA: 78592444728.13.B043174 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf16.hostedemail.com (Postfix) with ESMTP id 23382F00008C for ; Thu, 16 Sep 2021 06:23:24 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C7DAF611CE; Thu, 16 Sep 2021 06:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631773403; bh=/mzaUD2d9akaAwvFkDgrigFT4t5fTa72cmL+q0QWvg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y0GeuSsr4FJMqu42IPgaGS3jhH7OPsG31ZG22HnqFbdajQUxCg5NeXKmyI43dHRIP ykj2clvM6YASAHW8E/TGm9qetM9Z1BC7xiea9FgZFkVs0H/LzNfEjh4tuco7vyVuKY 64KIyQausHc3LNcbPy0hnVNOz+R1kiZylAmnlYR71M/cCR0bGmiu3mEpF4bip7S+GF lBvPOaY/pbMekfYANVjN+aj94SoV4M6a0hSkU7XgF0pXPldbwCRbxDdGs1VcHtiBxz kLdUWvWsbBYt/2BD08X8JEHl5sDBaXDHyLtcEyLnuIKiUNHRntNeNUSEQXrDHc9pK5 NcXAlO+ISny8A== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v4 2/4] bootconfig: Allocate xbc_data inside xbc_init() Date: Thu, 16 Sep 2021 15:23:20 +0900 Message-Id: <163177339986.682366.898762699429769117.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163177338366.682366.5998343833719057348.stgit@devnote2> References: <163177338366.682366.5998343833719057348.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Y0GeuSsr; spf=pass (imf16.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 23382F00008C X-Stat-Signature: t7pu1u5aj4ed3t6fus7qx7u7cudjrdt6 X-HE-Tag: 1631773404-763666 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Allocate 'xbc_data' in the xbc_init() so that it does not need to care about the ownership of the copied data. Suggested-by: Steven Rostedt Signed-off-by: Masami Hiramatsu --- include/linux/bootconfig.h | 2 +- init/main.c | 13 ++----------- lib/bootconfig.c | 33 +++++++++++++++++++++------------ tools/bootconfig/main.c | 6 +++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h index 537e1b991f11..62e09b788172 100644 --- a/include/linux/bootconfig.h +++ b/include/linux/bootconfig.h @@ -271,7 +271,7 @@ static inline int __init xbc_node_compose_key(struct xbc_node *node, } /* XBC node initializer */ -int __init xbc_init(char *buf, const char **emsg, int *epos); +int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos); /* XBC cleanup data structures */ diff --git a/init/main.c b/init/main.c index 0b054fff8e92..77c309ed9f17 100644 --- a/init/main.c +++ b/init/main.c @@ -410,7 +410,7 @@ static void __init setup_boot_config(void) const char *msg; int pos; u32 size, csum; - char *data, *copy, *err; + char *data, *err; int ret; /* Cut out the bootconfig data even if we have no bootconfig option */ @@ -443,16 +443,7 @@ static void __init setup_boot_config(void) return; } - copy = memblock_alloc(size + 1, SMP_CACHE_BYTES); - if (!copy) { - pr_err("Failed to allocate memory for bootconfig\n"); - return; - } - - memcpy(copy, data, size); - copy[size] = '\0'; - - ret = xbc_init(copy, &msg, &pos); + ret = xbc_init(data, size, &msg, &pos); if (ret < 0) { if (pos < 0) pr_err("Failed to init bootconfig: %s.\n", msg); diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 5ae248b29373..66b02fddfea8 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -789,6 +789,7 @@ static int __init xbc_verify_tree(void) */ void __init xbc_destroy_all(void) { + memblock_free_ptr(xbc_data, xbc_data_size); xbc_data = NULL; xbc_data_size = 0; xbc_node_num = 0; @@ -799,19 +800,20 @@ void __init xbc_destroy_all(void) /** * xbc_init() - Parse given XBC file and build XBC internal tree - * @buf: boot config text + * @data: The boot config text original data + * @size: The size of @data * @emsg: A pointer of const char * to store the error message * @epos: A pointer of int to store the error position * - * This parses the boot config text in @buf. @buf must be a - * null terminated string and smaller than XBC_DATA_MAX. + * This parses the boot config text in @data. @size must be smaller + * than XBC_DATA_MAX. * Return the number of stored nodes (>0) if succeeded, or -errno * if there is any error. * In error cases, @emsg will be updated with an error message and * @epos will be updated with the error position which is the byte offset * of @buf. If the error is not a parser error, @epos will be -1. */ -int __init xbc_init(char *buf, const char **emsg, int *epos) +int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) { char *p, *q; int ret, c; @@ -824,28 +826,35 @@ int __init xbc_init(char *buf, const char **emsg, int *epos) *emsg = "Bootconfig is already initialized"; return -EBUSY; } - - ret = strlen(buf); - if (ret > XBC_DATA_MAX - 1 || ret == 0) { + if (size > XBC_DATA_MAX || size == 0) { if (emsg) - *emsg = ret ? "Config data is too big" : + *emsg = size ? "Config data is too big" : "Config data is empty"; return -ERANGE; } + xbc_data = memblock_alloc(size + 1, SMP_CACHE_BYTES); + if (!xbc_data) { + if (emsg) + *emsg = "Failed to allocate bootconfig data"; + return -ENOMEM; + } + memcpy(xbc_data, data, size); + xbc_data[size] = '\0'; + xbc_data_size = size + 1; + xbc_nodes = memblock_alloc(sizeof(struct xbc_node) * XBC_NODE_MAX, SMP_CACHE_BYTES); if (!xbc_nodes) { if (emsg) *emsg = "Failed to allocate bootconfig nodes"; + xbc_destroy_all(); return -ENOMEM; } memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX); - xbc_data = buf; - xbc_data_size = ret + 1; - last_parent = NULL; - p = buf; + last_parent = NULL; + p = xbc_data; do { q = strpbrk(p, "{}=+;:\n#"); if (!q) { diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index fd67496a947f..7269c9e35335 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -229,7 +229,7 @@ static int load_xbc_from_initrd(int fd, char **buf) return -EINVAL; } - ret = xbc_init(*buf, &msg, NULL); + ret = xbc_init(*buf, size, &msg, NULL); /* Wrong data */ if (ret < 0) { pr_err("parse error: %s.\n", msg); @@ -269,7 +269,7 @@ static int init_xbc_with_error(char *buf, int len) if (!copy) return -ENOMEM; - ret = xbc_init(buf, &msg, &pos); + ret = xbc_init(buf, len, &msg, &pos); if (ret < 0) show_xbc_error(copy, msg, pos); free(copy); @@ -382,7 +382,7 @@ static int apply_xbc(const char *path, const char *xbc_path) memcpy(data, buf, size); /* Check the data format */ - ret = xbc_init(buf, &msg, &pos); + ret = xbc_init(buf, size, &msg, &pos); if (ret < 0) { show_xbc_error(data, msg, pos); free(data); From patchwork Thu Sep 16 06:23:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12498129 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, 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 B3DA3C433F5 for ; Thu, 16 Sep 2021 06:23:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 61381611EE for ; Thu, 16 Sep 2021 06:23:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 61381611EE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F3E5094000A; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEE546B0072; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDCB194000A; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id D0DDC6B0071 for ; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7278F2D4B5 for ; Thu, 16 Sep 2021 06:23:32 +0000 (UTC) X-FDA: 78592445064.08.2C25198 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf17.hostedemail.com (Postfix) with ESMTP id 2A875F00039C for ; Thu, 16 Sep 2021 06:23:32 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CF8760E76; Thu, 16 Sep 2021 06:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631773411; bh=HDO3TKu02v6+e848DWht3XEAfdCaWsoKu5YHLC4JMMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYocb8eZ7/3/FZNxFtfy4rmfts/5jPeYqyzVudGgOhlnWeo6URPWpIH3jWe52h5RX umQmP3i1EXTTYgHvUaL9k017EwR/ZfRY+XVrkZjs2A2K9wvrTQ82e6tt3R8MKirRh0 VJq9joDDkXgjpSz91ti03fq2lxmNdoi79vrlsBhZYHryLqKdDog1c2PMnevdET7go6 aC1673yP/ACsgylD1rXW0dNbCpjgyqGBX4/c1g8lW0T+75YMN0K8mcQxYeRhOpr4R6 gdV2GL1pARj4BYvFZEIkuB86pPUsttzpJUWx6SAdVLK+y9I5z5+A5OSu+fKW7zrnXE PheReHNkSBAkA== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v4 3/4] bootconfig: Add xbc_get_info() for the node information Date: Thu, 16 Sep 2021 15:23:29 +0900 Message-Id: <163177340877.682366.4360676589783197627.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163177338366.682366.5998343833719057348.stgit@devnote2> References: <163177338366.682366.5998343833719057348.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SYocb8eZ; spf=pass (imf17.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: ajyognk37w19xsawrs4qr74bbs1e54kz X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2A875F00039C X-HE-Tag: 1631773412-164607 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add xbc_get_info() API which allows user to get the number of used xbc_nodes and the size of bootconfig data. This is also useful for checking the bootconfig is initialized or not. Signed-off-by: Masami Hiramatsu --- include/linux/bootconfig.h | 2 ++ init/main.c | 1 + lib/bootconfig.c | 21 +++++++++++++++++++++ tools/bootconfig/main.c | 1 + 4 files changed, 25 insertions(+) diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h index 62e09b788172..f955bb7eabbb 100644 --- a/include/linux/bootconfig.h +++ b/include/linux/bootconfig.h @@ -273,6 +273,8 @@ static inline int __init xbc_node_compose_key(struct xbc_node *node, /* XBC node initializer */ int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos); +/* XBC node and size information */ +int __init xbc_get_info(int *node_size, size_t *data_size); /* XBC cleanup data structures */ void __init xbc_destroy_all(void); diff --git a/init/main.c b/init/main.c index 77c309ed9f17..747b4fd38a1a 100644 --- a/init/main.c +++ b/init/main.c @@ -451,6 +451,7 @@ static void __init setup_boot_config(void) pr_err("Failed to parse bootconfig: %s at %d.\n", msg, pos); } else { + xbc_get_info(&ret, NULL); pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret); /* keys starting with "kernel." are passed via cmdline */ extra_command_line = xbc_make_cmdline("kernel"); diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 66b02fddfea8..b088fe5c0001 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -34,6 +34,27 @@ static int xbc_err_pos __initdata; static int open_brace[XBC_DEPTH_MAX] __initdata; static int brace_index __initdata; +/** + * xbc_get_info() - Get the information of loaded boot config + * node_size: A pointer to store the number of nodes. + * data_size: A pointer to store the size of bootconfig data. + * + * Get the number of used nodes in @node_size if it is not NULL, + * and the size of bootconfig data in @data_size if it is not NULL. + * Return 0 if the boot config is initialized, or return -ENODEV. + */ +int __init xbc_get_info(int *node_size, size_t *data_size) +{ + if (!xbc_data) + return -ENODEV; + + if (node_size) + *node_size = xbc_node_num; + if (data_size) + *data_size = xbc_data_size; + return 0; +} + static int __init xbc_parse_error(const char *msg, const char *p) { xbc_err_msg = msg; diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 7269c9e35335..4f2a8d884745 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -391,6 +391,7 @@ static int apply_xbc(const char *path, const char *xbc_path) return ret; } printf("Apply %s to %s\n", xbc_path, path); + xbc_get_info(&ret, NULL); printf("\tNumber of nodes: %d\n", ret); printf("\tSize: %u bytes\n", (unsigned int)size); printf("\tChecksum: %d\n", (unsigned int)csum); From patchwork Thu Sep 16 06:23:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12498131 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, 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 65740C433F5 for ; Thu, 16 Sep 2021 06:23:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1750F61207 for ; Thu, 16 Sep 2021 06:23:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1750F61207 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BBB736B0071; Thu, 16 Sep 2021 02:23:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6B4594000C; Thu, 16 Sep 2021 02:23:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5A2C94000B; Thu, 16 Sep 2021 02:23:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 98DBF6B0071 for ; Thu, 16 Sep 2021 02:23:40 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 52C3118034ABE for ; Thu, 16 Sep 2021 06:23:40 +0000 (UTC) X-FDA: 78592445400.09.382AABA Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf01.hostedemail.com (Postfix) with ESMTP id 002E8505AE72 for ; Thu, 16 Sep 2021 06:23:39 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 30F68611CE; Thu, 16 Sep 2021 06:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631773419; bh=jUOjgA/pqgEKUiSJMHB1W97cBrtZ/aj/ifdF80aUG88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=des2/O1EBnaGhU1MX6s/eikyoHDaUEeMGiBmkJGhQHSmMwuvKGqEibLwdm7HTKoBY m4ZMS/gZfVVaTptewRGoawoyxgKj71OPGGSJBNP4YKxSJMUSe0nHGVYv38TdlFGtfA 2a93FKqD1dBrgIlGg7u4dx4VDunp+t6BsFpI7B4BqH3+6pWmgUt8/bhPfIxv/QDAWf STm/Z0twzrwuHtLveM982iNt6yCEPzEwCr6A0K+sl6FQKNE4FfPJgiOYibv/Q4QI8y sQQmK1l/qSrVbHVanWqRjaVPG0y6nkmG8qxY/iTFJLVlJFkbOEPq652oKuESXH9lRC geqCXkcZnfomw== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v4 4/4] bootconfig: Rename xbc_destroy_all() to xbc_fini() Date: Thu, 16 Sep 2021 15:23:36 +0900 Message-Id: <163177341667.682366.1520674275752512771.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163177338366.682366.5998343833719057348.stgit@devnote2> References: <163177338366.682366.5998343833719057348.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="des2/O1E"; spf=pass (imf01.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 002E8505AE72 X-Stat-Signature: ogyf43jg19gzptr36pwfpr3cw87fh3xi X-HE-Tag: 1631773419-376168 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Avoid using this noisy name and use more calm one. This is just a name change. No functional change. Signed-off-by: Masami Hiramatsu --- include/linux/bootconfig.h | 2 +- init/main.c | 2 +- lib/bootconfig.c | 8 ++++---- tools/bootconfig/main.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h index f955bb7eabbb..ba40194a339c 100644 --- a/include/linux/bootconfig.h +++ b/include/linux/bootconfig.h @@ -277,7 +277,7 @@ int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos); int __init xbc_get_info(int *node_size, size_t *data_size); /* XBC cleanup data structures */ -void __init xbc_destroy_all(void); +void __init xbc_fini(void); /* Debug dump functions */ void __init xbc_debug_dump(void); diff --git a/init/main.c b/init/main.c index 747b4fd38a1a..99a23324d4a1 100644 --- a/init/main.c +++ b/init/main.c @@ -463,7 +463,7 @@ static void __init setup_boot_config(void) static void __init exit_boot_config(void) { - xbc_destroy_all(); + xbc_fini(); } #else /* !CONFIG_BOOT_CONFIG */ diff --git a/lib/bootconfig.c b/lib/bootconfig.c index b088fe5c0001..43a402b02748 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -802,13 +802,13 @@ static int __init xbc_verify_tree(void) } /** - * xbc_destroy_all() - Clean up all parsed bootconfig + * xbc_fini() - Clean up all parsed bootconfig * * This clears all data structures of parsed bootconfig on memory. * If you need to reuse xbc_init() with new boot config, you can * use this. */ -void __init xbc_destroy_all(void) +void __init xbc_fini(void) { memblock_free_ptr(xbc_data, xbc_data_size); xbc_data = NULL; @@ -869,7 +869,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) if (!xbc_nodes) { if (emsg) *emsg = "Failed to allocate bootconfig nodes"; - xbc_destroy_all(); + xbc_fini(); return -ENOMEM; } memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX); @@ -925,7 +925,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) *epos = xbc_err_pos; if (emsg) *emsg = xbc_err_msg; - xbc_destroy_all(); + xbc_fini(); } else ret = xbc_node_num; diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 4f2a8d884745..84808a1871f0 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -397,7 +397,7 @@ static int apply_xbc(const char *path, const char *xbc_path) printf("\tChecksum: %d\n", (unsigned int)csum); /* TODO: Check the options by schema */ - xbc_destroy_all(); + xbc_fini(); free(buf); /* Remove old boot config if exists */