Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3DE50C19F2A for ; Sat, 30 Jul 2022 21:54:01 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4B632841D5; Sat, 30 Jul 2022 23:53:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="VQRqWWwp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7CD41841A8; Sat, 30 Jul 2022 23:53:15 +0200 (CEST) Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3A5B88418A for ; Sat, 30 Jul 2022 23:53:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x32d.google.com with SMTP id q6-20020a05683033c600b0061d2f64df5dso4179776ott.13 for ; Sat, 30 Jul 2022 14:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=AWQre9y7W8yrrWo78U0fgGt9N3a9FLsORfBNRXw9t7s=; b=VQRqWWwpbHOtCwaSERtTDp8arEt91TtZWPhQHmwbIdkoRGjXrTxPbXS65XIjuREcOR qtLBf+iDuhIv8/UhIdMyfcLT/XPxqQ4BhSDeEr+897JGPAoC6hkyQj1CHA3DxI1Bh6TG htqruprJfJxz/AjfmtV1UNeA0JbRWGRpuqtsM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=AWQre9y7W8yrrWo78U0fgGt9N3a9FLsORfBNRXw9t7s=; b=7OqmsJ4ZWnXysnZSoNC/ZqP/oKeLB/Sia7b7KwJV51/KcGOSuu6xDAPgMd2AFsNL3a lyrU/sapMu0MUrJBmTzRJWHnNuzrXHcdFgL0X/swUqwikmICXGmoYqPcTUZz12Y90hJx sCarY55AH0mkVxKOGLgdXPmnhJ4QO0JYIJR2kMvQhpqIn09UJCj/JN4tnatXyM+TN1xj qB0SlB+1rOJViFKXETmsgZmTtWDNLAH3buPeLNNLhyyxl/DX6tM2004zL37lbk7rIKLG gyTZOUlNSwJJn4Nq9KO66PO7cF7Gn4vZOgA94uQPJZ/1BtyymxWHOp/Nbrdx6pjYznrC 1A1Q== X-Gm-Message-State: AJIora+5BlLq6hLEvxlCQpQ89NoVRwtsDrx11imKLtKz0EiCMa5etnzn qH0faDvBgcDEC2bX/axobBZd3hIGwhrufUvS X-Google-Smtp-Source: AGRyM1uuGd5m4i90enxyox2N650Wg5Sog0jGdfTVE84XaJ6nfM8pqGLBzDxBsQ3uPjJtZ/B7tM2jUQ== X-Received: by 2002:a05:6830:630f:b0:61c:7c8b:ed18 with SMTP id cg15-20020a056830630f00b0061c7c8bed18mr3850781otb.168.1659217987684; Sat, 30 Jul 2022 14:53:07 -0700 (PDT) Received: from sjg1.lan (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id 19-20020a544193000000b0032f75714af1sm1699656oiy.18.2022.07.30.14.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 14:53:07 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Bin Meng , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH v2 05/35] dm: core: Add a note about how livetree updates work Date: Sat, 30 Jul 2022 15:52:07 -0600 Message-Id: <20220730215237.818368-4-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog In-Reply-To: <20220730215237.818368-1-sjg@chromium.org> References: <20220730215237.818368-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The unflattening algorithm results in a single block of memory being allocated for the whole tree. When writing new properties, these are allocated new memory outside that block. When the block is freed, the allocated properties remain. Document how this works and the potential memory leak, as well as mentioning that updating the livetree is actually supported now. Signed-off-by: Simon Glass --- (no changes since v1) doc/develop/driver-model/livetree.rst | 17 +++++++++++++---- include/dm/ofnode.h | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/doc/develop/driver-model/livetree.rst b/doc/develop/driver-model/livetree.rst index 9f654f3b894..fb2969259d0 100644 --- a/doc/develop/driver-model/livetree.rst +++ b/doc/develop/driver-model/livetree.rst @@ -211,9 +211,18 @@ using it in new code. Modifying the livetree ---------------------- -This is not currently supported. Once implemented it should provide a much -more efficient implementation for modification of the device tree than using -the flat tree. +This is supported in a limited way, with ofnode_write_prop() and related +functions. + +The unflattening algorithm results in a single block of memory being +allocated for the whole tree. When writing new properties, these are +allocated new memory outside that block. When the block is freed, the +allocated properties remain. This can result in a memory leak. + +The solution to this leak would be to add a flag for properties (and nodes when +support is provided for adding those) that indicates that they should be +freed. Then the tree can be scanned for these 'separately allocated' nodes and +properties before freeing the memory block. Internal implementation @@ -281,6 +290,6 @@ Live tree support was introduced in U-Boot 2017.07. There is still quite a bit of work to do to flesh this out: - tests for all access functions -- support for livetree modification +- more support for livetree modification - addition of more access functions as needed - support for livetree in SPL and before relocation (if desired) diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 346b09c7d96..5a5309d79a7 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1081,7 +1081,8 @@ int ofnode_device_is_compatible(ofnode node, const char *compat); * ofnode_write_prop() - Set a property of a ofnode * * Note that the value passed to the function is *not* allocated by the - * function itself, but must be allocated by the caller if necessary. + * function itself, but must be allocated by the caller if necessary. However + * it does allocate memory for the property struct and name. * * @node: The node for whose property should be set * @propname: The name of the property to set -- 2.37.1.455.g008518b4e5-goog