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 B068CC433EF for ; Wed, 20 Jul 2022 17:01:08 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BDA8F84084; Wed, 20 Jul 2022 19:00:31 +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="OAkxMnGQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 38973840EE; Wed, 20 Jul 2022 19:00:25 +0200 (CEST) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (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 87927840AE for ; Wed, 20 Jul 2022 19:00:15 +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-wm1-x332.google.com with SMTP id b6so10723890wmq.5 for ; Wed, 20 Jul 2022 10:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w7ulEtknZcrvOI5QJgAM+siadX4E7KE7PH3/AN3MvRs=; b=OAkxMnGQk2weX5dsMPkESZ49GB31dbzvOSM84Ue1dt5Qnc072b2GsXgLFCPt5zqkyp VOwB7+9yqStvLBsujLnfBOMwV2sAfjN4+u763dY0jIfka/35Oeys65prKFDl7xrSng3u 3tjctAVf2Tcw/3Xb9UELx1M+Ye1U/mhwZPKe0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w7ulEtknZcrvOI5QJgAM+siadX4E7KE7PH3/AN3MvRs=; b=YiwpRTtPdK9VE7LTZW2sqi1XiTpM9mmH9c4gTdudZq6wlghItRC4IfZpaF1Z6HOijz oePTZ+9JCmhm1zEgN20Ne4MBvAi+QsimGaTLLnhw00s3IACfopqvSJKDtNGPZQ6h9YGj g3kTat8wYV1dJkKsZUFbRoEld71NhJ5c3GuSbun7Mtpkguiqj9fmVuFRWxW9jE3ttxd8 4uKeBlhehVlwIm21+QSl5j5fgqJ9ROZaMyA4mE2l9Te639VmLTzQqdJXbYohHOrNk8Ra /qyYPH2aanlXQygC3ZMY168LJ1UTsgFgAAUiQUtOZQJ3BZr9XZ06RqnUIgnUEh1Z4KyI Kt1w== X-Gm-Message-State: AJIora+NBkRWHV4vKwdeP1Y7V0Z6WKQ2WZajSg+xNHIihrxf6hjmlQJq 2optp7AYIFX+YVk4v/OCPcvlXaT0OqpAXq8v X-Google-Smtp-Source: AGRyM1u4GkfUYESmtbs+ktkhsN6e3o22fta3ayxdX4KqgDjM172T3exkbFPvc64Rg6CN0Rm7EHFQGw== X-Received: by 2002:a7b:c4cc:0:b0:3a3:2123:8c1b with SMTP id g12-20020a7bc4cc000000b003a321238c1bmr4754774wmk.180.1658336414394; Wed, 20 Jul 2022 10:00:14 -0700 (PDT) Received: from sjg1.roam.corp.google.com ([62.48.169.138]) by smtp.gmail.com with ESMTPSA id u16-20020a05600c00d000b003a31c4f6f74sm3690906wmm.32.2022.07.20.10.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 10:00:13 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH 04/19] ofnode: Add a note about how livetree updates work Date: Wed, 20 Jul 2022 10:59:32 -0600 Message-Id: <20220720165947.12728-5-sjg@chromium.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220720165947.12728-1-sjg@chromium.org> References: <20220720165947.12728-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 --- 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.0.170.g444d1eabd0-goog