Message ID | 163166721027.510331.6820619440348067061.stgit@devnote2 (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | bootconfig: Fixes to bootconfig memory management | expand |
On Tue, Sep 14, 2021 at 5:53 PM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > Free copied bootconfig data after booting kernel because that > data will not be used anymore. Don't do this. You have already passed in that 'copy' to the xbc code, and xbc_destroy_all() should just free it. Don't add new pointless variables to keep track of state that somebody else already keeps track of. Linus
On Tue, 14 Sep 2021 18:13:51 -0700 Linus Torvalds <torvalds@linux-foundation.org> wrote: > On Tue, Sep 14, 2021 at 5:53 PM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > > > Free copied bootconfig data after booting kernel because that > > data will not be used anymore. > > Don't do this. > > You have already passed in that 'copy' to the xbc code, and > xbc_destroy_all() should just free it. > > Don't add new pointless variables to keep track of state that somebody > else already keeps track of. Ah, OK. So when I pass the copy, the ownership should be passed too. Thank you, > > Linus
diff --git a/init/main.c b/init/main.c index 4f059fde1df0..0148152652e9 100644 --- a/init/main.c +++ b/init/main.c @@ -319,6 +319,8 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) #ifdef CONFIG_BOOT_CONFIG static char xbc_namebuf[XBC_KEYLEN_MAX] __initdata; +static void *init_xbc_data_copy __initdata; +static phys_addr_t init_xbc_data_size __initdata; #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0) @@ -466,12 +468,17 @@ static void __init setup_boot_config(void) extra_command_line = xbc_make_cmdline("kernel"); /* Also, "init." keys are init arguments */ extra_init_args = xbc_make_cmdline("init"); + init_xbc_data_copy = copy; + init_xbc_data_size = size + 1; } return; } static void __init exit_boot_config(void) { + if (!init_xbc_data_copy) + return; + memblock_free_ptr(init_xbc_data_copy, init_xbc_data_size); xbc_destroy_all(); }
Free copied bootconfig data after booting kernel because that data will not be used anymore. commit 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") freed the bootconfig xbc_node array after booting kernel, but forgot to free the bootconfig data itself. This fixes that to free the bootconfig data too. Fixes: 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> --- Changes in v2: - Split memblock leak fix because it fixes another commit. - Use memblock_free_ptr() --- init/main.c | 7 +++++++ 1 file changed, 7 insertions(+)