Message ID | 163166718582.510331.11732633028925882626.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: > > Fix to check the xbc_node is used before calling memblock_free() > because passing NULL to phys_addr() will cause a panic. No. That's the previous bad situation. The whole point of memblock_free_ptr() is that it actually acts the way a memory freeing function *should*, and has no problems with NULL pointers. > - Rebase on top of Linus tree. Please don't do a mindless rebase, take the actual changes into account. Linus
On Tue, 14 Sep 2021 18:12:28 -0700 Linus Torvalds <torvalds@linux-foundation.org> wrote: > On Tue, Sep 14, 2021 at 5:53 PM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > > > Fix to check the xbc_node is used before calling memblock_free() > > because passing NULL to phys_addr() will cause a panic. > > No. > > That's the previous bad situation. > > The whole point of memblock_free_ptr() is that it actually acts the > way a memory freeing function *should*, and has no problems with NULL > pointers. Oops, sorry. Please drop it. > > > - Rebase on top of Linus tree. > > Please don't do a mindless rebase, take the actual changes into account. Sorry about that. I missed the change. Thank you, > > Linus
diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 5ae248b29373..bee691ea8213 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -792,7 +792,8 @@ void __init xbc_destroy_all(void) xbc_data = NULL; xbc_data_size = 0; xbc_node_num = 0; - memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); + if (xbc_nodes) + memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); xbc_nodes = NULL; brace_index = 0; }
Fix to check the xbc_node is used before calling memblock_free() because passing NULL to phys_addr() will cause a panic. This will happen if user doesn't pass any bootconfig to the kernel, because kernel will call xbc_destroy_all() after booting. Fixes: 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") Reported-by: kernel test robot <oliver.sang@intel.com> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> --- Changes in v2: - Rebase on top of Linus tree. --- lib/bootconfig.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)