linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Mike Rapoport <rppt@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>, Linux-MM <linux-mm@kvack.org>,
	Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [PATCH v3 3/3] bootconfig: Free xbc_data in xbc_destroy_all()
Date: Thu, 16 Sep 2021 09:05:03 +0900	[thread overview]
Message-ID: <20210916090503.c9d8209e8c88e9c4c7d3072c@kernel.org> (raw)
In-Reply-To: <20210915102354.2841798d@oasis.local.home>

On Wed, 15 Sep 2021 10:23:54 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Wed, 15 Sep 2021 22:19:52 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > @@ -810,6 +811,8 @@ void __init xbc_destroy_all(void)
> >   * 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.
> > + * Note that the @buf ownership is transferred, so it will be freed
> > + * in xbc_destroy_all().
> >   */
> >  int __init xbc_init(char *buf, const char **emsg, int *epos)
> >  {
> 
> I hate this "ownership transfer". Looking at the use case here:
> 
> init/main.c:
> 
> 	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);
> 	if (ret < 0) {
> 
> Instead of having xbc_init() return the node count on success, how about
> having it allocate the buffer to use and then return it?
> 
> That is, move the:
> 
> 	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';
> 
> into xbc_init(), and have data, and size be passed to it.
> 
> Then, have it return the pointer of "copy" or NULL on error?

Thanks for pointing it out, that is also good to me.
Let me update it.

> 
> This will keep the semantics of xbc_* owning the buffer that gets
> freed by the destroy.
> 
> The xbc_init() could also do the pr_info() that prints the bytes and
> node count. There's no other reason to pass that node count to the
> caller, is there?

Ah, it is my policy that the error or information message is shown
by caller (since caller can also ignore that, e.g. passing the
testing data), not from the library code.
I learned that from perf-probe and ftrace, sometimes the library
code reused in unexpected way. So I decided to decouple the
generating error message and showing it.

Thank you,

> 
> -- Steve


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2021-09-16  0:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15 13:19 [PATCH v3 0/3] bootconfig: Fixes to bootconfig memory management Masami Hiramatsu
2021-09-15 13:19 ` [PATCH v3 1/3] bootconfig: init: Fix memblock leak in xbc_make_cmdline() Masami Hiramatsu
2021-09-15 13:19 ` [PATCH v3 2/3] bootconfig: init: Fix memblock leak in setup_boot_config() Masami Hiramatsu
2021-09-15 13:19 ` [PATCH v3 3/3] bootconfig: Free xbc_data in xbc_destroy_all() Masami Hiramatsu
2021-09-15 14:23   ` Steven Rostedt
2021-09-16  0:05     ` Masami Hiramatsu [this message]
2021-09-16  0:17       ` Steven Rostedt
2021-09-15 16:47 ` [PATCH v3 0/3] bootconfig: Fixes to bootconfig memory management Linus Torvalds
2021-09-15 16:51   ` Linus Torvalds
2021-09-16  0:07     ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210916090503.c9d8209e8c88e9c4c7d3072c@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).