From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_2 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 764CDC433F5 for ; Wed, 15 Sep 2021 14:24:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AA77461130 for ; Wed, 15 Sep 2021 14:24:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AA77461130 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 366D2900002; Wed, 15 Sep 2021 10:24:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33D666B0072; Wed, 15 Sep 2021 10:24:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27A84900002; Wed, 15 Sep 2021 10:24:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id 193526B0071 for ; Wed, 15 Sep 2021 10:24:04 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C2D9E82499A8 for ; Wed, 15 Sep 2021 14:24:03 +0000 (UTC) X-FDA: 78590027166.17.3A641E1 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf04.hostedemail.com (Postfix) with ESMTP id 6005B5000300 for ; Wed, 15 Sep 2021 14:24:03 +0000 (UTC) Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A6DF46113E; Wed, 15 Sep 2021 14:24:01 +0000 (UTC) Date: Wed, 15 Sep 2021 10:23:54 -0400 From: Steven Rostedt To: Masami Hiramatsu Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Linux-MM , Vlastimil Babka Subject: Re: [PATCH v3 3/3] bootconfig: Free xbc_data in xbc_destroy_all() Message-ID: <20210915102354.2841798d@oasis.local.home> In-Reply-To: <163171199244.590070.6356174550728998874.stgit@devnote2> References: <163171196689.590070.15063104707696447188.stgit@devnote2> <163171199244.590070.6356174550728998874.stgit@devnote2> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of "SRS0=5kbo=OF=goodmis.org=rostedt@kernel.org" designates 198.145.29.99 as permitted sender) smtp.mailfrom="SRS0=5kbo=OF=goodmis.org=rostedt@kernel.org" X-Stat-Signature: 3jy8nwy34tw1karmufzh7rxpm8h8z7xd X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6005B5000300 X-HE-Tag: 1631715843-783058 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: On Wed, 15 Sep 2021 22:19:52 +0900 Masami Hiramatsu 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? 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? -- Steve