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 A8C0EECAAA1 for ; Wed, 31 Aug 2022 03:10:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 10137849EF; Wed, 31 Aug 2022 05:09:58 +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="P/jgIW9f"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D1BC849B9; Wed, 31 Aug 2022 05:09:39 +0200 (CEST) Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) (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 6EF50849B5 for ; Wed, 31 Aug 2022 05:09: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=sjg@chromium.org Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-11e9a7135easo18866285fac.6 for ; Tue, 30 Aug 2022 20:09:31 -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:subject:date; bh=+5yNcGdV+lKQOuWMRiYxJQBqxw6Xk/lerc4y6C6CRTk=; b=P/jgIW9fOtSg0dXltlIce+qybJEnFc4mXx0uFGLUIKv6hQ+aypTDDL9jI+7nFl1+DA WQcX6eRpgPIjYnxMZKrJpu3ont007jAitgJL7XfrCqj42aKPM76n/SEcJEDM0Tq8KDvF oM1XyBJHdxG4DmbSHR56tEEZ+8koFpzlNOhuQ= 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 :subject:date; bh=+5yNcGdV+lKQOuWMRiYxJQBqxw6Xk/lerc4y6C6CRTk=; b=HyvMeJgPfbBPkNCM/eLL3hfiT66htRktnD7qgmilKLobCKjZc2KTPTynKZlhrIX6KW umoDVtYfxummardMg43uW1JF8snlqZdCa9kFdLtZa6/Kn5LMJVN9gie85yVAYSVbBnyg sWq0OBUtLKsR8tdmMyEkpCeZCoIizbS9ZEHHo/ldeHbEQD3JQagOCq64veByX2IDH+1b cBCE46OYO9E3ftu8GohOCaJKiQ+LWdNi49BTYAy01Ir2GbPyHRGAMV2wWtEVMT0G1me9 fdfLMwRDMy10YvSRLWo7PAztzJZM1V6g2wsxHpHIs781r65GZeuH/VsISYU0sJMUyfeS wdvA== X-Gm-Message-State: ACgBeo27HUm5svX8ysmCCtsoZj1kQVLcd9DgpFMWqV7tqZfYfxlELYat /1e1FN+HVRoYq1IWGMfQ3bGzgaNjnyUUfw== X-Google-Smtp-Source: AA6agR6ie839conUMWalh5KSJ9WdmUYUXv8VbNISs4qBI66OKKeYYROxk1U2oZtXg417vz6rqCkxrw== X-Received: by 2002:a05:6870:a104:b0:11d:4448:70e3 with SMTP id m4-20020a056870a10400b0011d444870e3mr532191oae.168.1661915348583; Tue, 30 Aug 2022 20:09:08 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id fp39-20020a05687065a700b00116d5103487sm9282605oab.31.2022.08.30.20.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 20:09:08 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Kishon Vijay Abraham I , Tom Rini , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH 09/21] dm: core: Support writing a property to an empty node Date: Tue, 30 Aug 2022 21:08:05 -0600 Message-Id: <20220831030817.27804-10-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog In-Reply-To: <20220831030817.27804-1-sjg@chromium.org> References: <20220831030817.27804-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 At present this does not work with livetree. Fix it and add a test. Signed-off-by: Simon Glass --- drivers/core/of_access.c | 8 ++++---- test/dm/ofnode.c | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 765b21cecdb..cc5837a4a3b 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -909,9 +909,6 @@ int of_write_prop(struct device_node *np, const char *propname, int len, pp_last = pp; } - if (!pp_last) - return -ENOENT; - /* Property does not exist -> append new property */ new = malloc(sizeof(struct property)); if (!new) @@ -927,7 +924,10 @@ int of_write_prop(struct device_node *np, const char *propname, int len, new->length = len; new->next = NULL; - pp_last->next = new; + if (pp_last) + pp_last->next = new; + else + np->properties = new; return 0; } diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index f5aabf42dbb..76346e37d1f 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -612,6 +612,9 @@ static int dm_test_ofnode_add_subnode(struct unit_test_state *uts) check = ofnode_path("/lcd/edmund"); ut_asserteq(check.of_offset, subnode.of_offset); + /* write to the empty node */ + ut_assertok(ofnode_write_string(subnode, "compatible", "sandbox,usb")); + ut_asserteq(-EEXIST, ofnode_add_subnode(node, "edmund", &subnode)); return 0; -- 2.37.2.672.g94769d06f0-goog